Search code examples
javascriptjqueryobject-literal

jquery using object literal over multiple files


I've seen object literal examples and they look really nice and sensible. What I want to know is if it's possible to use object literal over multiple files, because all the examples I've seen had only 1 file.

Thanks.


Solution

  • At the top of each file you check to see if the object already exists.. if it does, then use the existing object.. if not then create a new object so you're not trying to work on an undefined variable.

    var object = object || {}
    
    object.doStuff = function () {}