forked from SparkDevNetwork/Rock
-
Notifications
You must be signed in to change notification settings - Fork 12
JavaScript Coding Standards
Jason Offutt edited this page May 2, 2013
·
6 revisions
If you're developing a block, and you need to register a JavaScript on the page in a way that will ensure that it does not get added more than once, there are a couple different ways to do it. We've exposed a method call on the CurrentPage object that will allow you to register your external JS file without worrying about collisions.
protected void OnLoad( EventArgs e )
{
base.OnLoad( e );
this.CurrentPage.AddScriptLink( this.Page, "~/Scripts/path-to-your-file.js" );
}Under the covers, this method uses ASP.NET's built in ScriptManager control to handle registering all JavaScript with the current page, and will ensure the same script file does not get added to the DOM more than once.
Crockford's style guide, JSLint and JSHint
- Manual variable hoisting
- Brace placement
-
withoperator - When it's OK to use
eval
JavaScript: The Good Parts