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' );
你在
var a = ObjectFactory( A, 'svenzeng' );
前面加一句
A.prototype = 10;
就是了。你这个永远都不会等于number,因为手机码字,所以点到为止,number是基本数据类型,而prototype是引用数据类型object