Recently I spent a number of hours banging my head against a wall trying to customize some of the rich DHTML functionality in SharePoint. Basically I wanted to remove the Workflows option from the default list item context menu (Edit Control Block).
I couldn't use a feature as this doesn't work for the built in elements and I didn't want to mess with CORE.js as it's never good practive and would effect all doc libs. So I worked out which method to override and then added this code inside PlaceHolderMain for the allitems.aspx page like so:
<script type="text/javascript">
function AddWorkflowsMenuItem(m, ctx)
{
//do nothing
}
</script>
The idea is that it will override the defualt behaviour of adding the menu with nothing - and hence not show the menu. For some reason this didn't work, in fact when debugged, the JavaScript was throwing an error. Interestingly it worked in FireFox so I knew I wasn't doing anything wrong. Initially I thought maybe this could be a browser compat thing but overriding a method is the same in any browser.
Eventually it dawned on me that the problem was the core.js script had not yet been loaded. The culprit was the ScriptLink control:
<SharePoint:ScriptLink language="javascript" name="core.js" Defer="true" runat="server"/>
Basically this control is referencing the CORE.js external javascript file. However becuase the defer tag is specified it is loaded after my function override is declared. This deferred loading is usually a good thing as the page doesn't have to halt it's loading for the script - instead it is loading in the background. This gives a perceived performance boost to the user.
In my case I was able to add the scriptlink without the defer tag to just the page I needed to (allitems.aspx). All other pages in the site can still benefit from the deferred loading and I get the desired functionality: