jquery - how to define global namespace in javascript -
is there way define global namespace, can call function namespace page?
e.g
// in 1 file define below code
definenamespace("my.namespace.api", { addobject: function(obj) { // store obj indexdb }, readallobject: function() { // return array of object indexdb } })
// in javascript file can do
my.namespace.api.addobject({name: "foo", desc: "bar"});
is there way implement "definenamespace" method?
thanks
one way it, simple, this:
my = { namespace: { api : {} } } my.namespace.api.addobject = function (obj) { }
you're creating objects in way function namespace :)
hm it's not method you're implementing. building namespace method require function called before script files loaded namespace used that, otherwise lines of code called before definenamespace method called , run parts of namespaces undefined @ point. above solution won't case, although not dynamic unfortunately.
Comments
Post a Comment