开发者

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 ob开发者_C百科ject literal over multiple files, because all the examples I've seen had only 1 file.

Thanks.


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 () {}


If you mean in web browsers, file scope is meaningless (unless you use WebWorkers, but I doubt you're at that stage yet). When you declare a global variable, it's available to all .js files you include in your html page. It doesn't matter if it's an object literal, function, string or whatever.

Functions/methods however do have their own scope, so if you declare variables inside a function, it's not global and thus not available to other code.

If that does not awnser your question, please be a bit more specific ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜