您的位置:首页 > 编程语言

Email页面代码书写建议及规范

2010-06-07 23:10 316 查看
function myNew(constructor) {
var obj = {
__proto__: constructor.prototype
};
constructor.apply(obj, Array.prototype.slice.call(arguments, 1));
return obj;
}

function MyTest(i) {
this.count = i;
}

var obj1 = myNew(MyTest, 0);
console.log(obj1.count);
console.log(obj1 instanceof MyTest);
console.log(obj1 instanceof Object);

function OtherTest(i, name, value) {
this.count = i;
this.name = name;
this.value = value;
}

var obj2 = myNew(OtherTest, 0, 'myName', 'myValue');
console.log(obj2);
console.log(obj2 instanceof MyTest);
console.log(obj2 instanceof OtherTest);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: