摘要:
1。工厂函数方法,不推荐:function ex(color,size){var obj = {};obj.color = color;obj.size = size;obj.say = function(){alert("工厂方法");}}var obj = ex("颜色值", "大小");obj.color;obj.say();2.构造方法:function ex(color, size){this.color = color;this.size = size;this.say = function(){ alert(" 阅读全文
摘要:
1。用函数构造A.声明时同时设置属性和方法function func(){this.name = "myname";this.say = function(){alert("i said:")}}引用时:var obj = new func();alert(obj.name);obj.say();B.先声明后使用: function func(){}var obj = new func();obj.name = "myname";obj.say = function(){alert("I said:")}引用时:a 阅读全文