function objectone(text){ //普通函数
var test=new Object();
test.t=300;
test.run = function(){
return (this.t - text );
}
return test;
}
function Objecttwo(text){ //构造函数 this相当于后台自动 new Object
this.t=300;
this.run = function(){
return (this.t - text );
}
//return this; 不需要return 不需要返回对象引用
}
// alert(Object1.run()); //299
// alert(Object2.run()); //299
// alert(Object1 instanceof Objectone); false//不可以识别对象
// alert(Object2 instanceof Objecttwo); true//可以识别对象引用是来自Objecttwo
//alert(Objecttwo("1")); //undefined //不可使用普通函数调用方法
var Object3 = new Object();
Objecttwo.call(Object3,2); //构造函数对象冒充
//alert(Object3.run()); //298 //不可使用普通函数调用方法
下一篇:[ECMAScript 6] 使用babel将ES6转换成ES5兼容更多浏览器
上一篇:[webpack]各种loader的安装和使用