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

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -