js模块化
//blog.js var blog = {};//初始化命名空间 blog.utility = { Version : 'blog.utility version 0.0.1', sayHello: function (str) { alert('hello : '+str +' by ' + this.getVersion()); }, getVersion :function () { return this.Version; } } ////////////////////////// //color.js var color = {};//初始化命名空间 color.utility= { Version : 'color.utility version 0.0.1', sayHello: function (str) { alert('hello : '+str +' by ' + this.getVersion()); }, getVersion :function () { return this.Version; } } //////////////////////// //调用 with (color.utility) { sayHello('fzg'); alert(getVersion()); } with (blog.utility) { sayHello('abc'); } |