Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Standards (proposed)

Code Files

Should put all code, other than $(document).ready() blocks, within self-executing closures with important namespaces passed in:

Code Block

// Example Widget
function(ns/*, data, utils*/){
    // Create Widget short name for local reference    exWdgt = {};

    // Use closures for private code    var testFunc();

    // Add all widget code to widget namespace.
    exWdgt.WidgetModel = can.Model({...});
    exWdgt.WidgetControl = can.Control({...});

    // Add an initialization function if the widget should be initialized externally
    exWdgt.initWidget = function(/*params*/){...};

    // Make sure to add widget namespace to ns namespace
    ns.ExampleWidget = exWdgt;

// Pass in external values that will be used by this code
}(
// ns should always be included, be first and be the specific namespace to which the resulting objects and functions from this file will be added.
raft.widgets, // ns
raft.data,    // data
raft.utils    // utils
));

$(document).ready(function()){
    // Code to run when document is finished loading
}

Utilities

Code Block

Misc:

- Always include both params when calling can.Model()

...