false.toNumber(); Boolean.prototype.toNumber = function () { console.log(this);//此时输出 [Boolean:false] 但如果直接用 this?1:0返回的话 console.log(typeof this); //object return this.valueOf() ? 1 : 0;//正确方法:this.valueOf()取得原始值 }
false.toNumber(); Boolean.prototype.toNumber = function () { console.log(this);//此时输出 [Boolean:false] 但如果直接用 this?1:0返回的话 console.log(typeof this); //object return this.valueOf() ? 1 : 0;//正确方法:this.valueOf()取得原始值 }