javascript - 如下代码,什么情况下typeof Constructor.prototype === 'number'?
巴扎黑
巴扎黑 2017-04-11 11:52:55
0
2
445
function A( name ){
    this.name = name;
}
 
function ObjectFactory(){
    //console.log(arguments);
    var obj = {},
    Constructor = Array.prototype.shift.call( arguments );
    //console.log(typeof Constructor.prototype);
    
    obj.__proto__ =  typeof Constructor.prototype === 'number'  ? Object.prototype : Constructor.prototype;
    
    var ret = Constructor.apply( obj, arguments );
    //console.log(typeof ret);
    
    return typeof ret === 'object' ? ret : obj;
    
}
 
var a = ObjectFactory( A, 'svenzeng' );
巴扎黑
巴扎黑

reply all(2)
洪涛

你在 var a = ObjectFactory( A, 'svenzeng' );
前面加一句 A.prototype = 10; 就是了。

Peter_Zhu

你这个永远都不会等于number,因为手机码字,所以点到为止,number是基本数据类型,而prototype是引用数据类型object

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!