标签:blog io ar sp for java strong on div
命名空间模式:
var MYAPP = MYAPP || {}; MYAPP.namespace = function (ns_string) { var parts = ns_string.split(‘.‘); parent = MYAPP; if(parts[0] === ‘MYAPP‘) { parts = parts.slice(1); } for(var i = 0; i < parts.length; i++) { if(typeof parent[parts[i]] === ‘undefined‘) { parent[parts[i]] = {}; } parent = parent[parts[i]]; } return parent; } var module2 = MYAPP.namespace(‘MYAPP.modules.module2‘);
如对于:MYAPP, MYAPP.util.Event, MYAPP.util.Dom; //在一个函数或模块顶部进行声明 var myFunc = function() { var event = MYAPP.util.Event; var dom = MYAPP.util.Dom; ................ }
解析局部变量的速度比解析全局变量快;
function Gadget() { var name = ‘iPod‘; this.getName = function () { return name; } }
注意,如果私有属性设置是一个对象,且只读,那么不要将它直接返回,而是返回其浅复制后的副本;
标签:blog io ar sp for java strong on div
原文地址:http://www.cnblogs.com/jinkspeng/p/4155238.html