var num = 0;
function Fn(num) {
arguments[0] = 100;
this.num = 200;
console.log(num);
console.log(this.num);
return num;
}
Fn.num = 400;
Fn.prototype.num = 300;
Fn.prototype.getNum = function () {
console.log(this.num);
};
var f = new Fn(num);
console.log(f.num);
f.getNum();
Fn.prototype.getNum();
console.log(num);
var n = Fn(num);
console.log(n);
console.log(num);
解析思路如下:
var num = 0;
function Fn(num) {
arguments[0] = 100;
this.num = 200;
console.log(num);//100
console.log(this.num);//200
return num;
}
Fn.num = 400;
Fn.prototype.num = 300;
Fn.prototype.getNum = function () {
console.log(this.num);
};
var f = new Fn(num);
console.log(f.num);//200
f.getNum();//200,
Fn.prototype.getNum();//300
console.log(num);//0
var n = Fn(num);
console.log(n);//100,200,100
console.log(num);//200