ECMAScript至于new Object时传参的片段细节

function Person(){this.name='jack';}
var p = new Person();
$.isPlainObject(new Object(4));        //-> false
$.isPlainObject(new Object('hello')); //-> false
$.isPlainObject(new Object(true));   //-> false
$.isPlainObject(new Object(p));       //-> false

ECMAScript,从以上看出,当传参数时,使用new
Object生成的目的其构造器不肯定指向Object,惟有很巧的时候会指向Object,如

2,
参数是主导项目对象,如字符串(String),数字(Number),布尔值(Boolean),将其卷入成靶子(转换成其相应的包装类)后赶回。

var obj1 = new Object,
    obj2 = {};
var o1 = new Object(obj1);
    o2 = new Object(obj2);

console.log(o1.constructor); //-> Object
console.log(o2.constructor); //-> Object

如上就能明了干吗jquery1.4+中以下代码重临false了

此地切磋给Object传参时,其内部的处理。参考:ECMA262 V5 15.2.2.1

var s = new Object('hello'),
    n = new Object(22),
    b = new Object(true);

console.log(typeof s); //-> Object
console.log(typeof n); //-> Object
console.log(typeof b); //-> Object

console.log(s.constructor); //-> String
console.log(n.constructor); //-> Number
console.log(b.constructor); //-> Boolean

1, 参数是一个目的,主题js对象(native ECMAScript object)或宿主对象(host
object),那么将一直回到该目标。

其生成的对象构造器如故是所传参数对象的构造器。那样造成的结局是固然该目标是new
Object,但其constructor不必然是Object。

function Person(){this.name='jack';}
var w = new Object(window),
    d = new Object(document),
    p = new Object(new Person());

console.log(w.constructor); //-> Window
console.log(d.constructor); //-> HTMLDocument
console.log(p.constructor); //-> Person