Where can I accommodate ready function in the name space?
var yourNamespace = yourNamespace || {
foo: function()
{
},
bar: function()
{
}
};
...
yourNamespace.foo();
ready function:
$(function(){
...
});
Here's how I do it:
var MyNamespace = (function(publicAPI) {
var foo = 'I am a private field';
publicAPI.alertFoo = function() {
alert(foo);
};
// DOM ready
$(function() {
$('.test-link').click(function() {
publicAPI.alertFoo();
});
});
return publicAPI;
})(MyNamespace || {});
To call the alertFoo method you would use MyNamespace.alertFoo(); This is a variation of the module pattern. The DOM ready section is used for binding to events.
MyNamespace should be the same as myModule…
readyfunction?foo()call? What do you mean by "in the namespace"?$(function(){ $('button').click(foo); });