// 命名空间 var MYAPP3 = MYAPP3 || {}; MYAPP3.demo = {}; MYAPP3.demo.Element = function(type,prop)
// 命名空间
var MYAPP3 = MYAPP3 || {};
MYAPP3.demo = {};
MYAPP3.demo.Element = function(type,prop){
var tem = document.createElement(type);
for(var i in prop){
tem.setAttribute(i,prop[i]);
}
return tem;
}
MYAPP3.demo.Text = function(txt){
return document.createTextNode(txt);
}
//两个全局变量下对象的方法,这样写减少了全局变量的使用,减少了命名冲突,达到了命名空间的效果
var a11 = new MYAPP3.demo.Element('a',{
href:"http://www.hao123.com",
class:"demo",
});
var a12 = new MYAPP3.demo.Text('点击我')
a11.appendChild(a12);
document.body.appendChild(a11);