JS Object() 与 new Object()的区别

//无意间看到这段代码
function inheritPrototype(subType,superType){
  var prototype = Object(superType.prototype);
  prototype.constructor = subType;
  subType.prototype = prototype;
}

// 以上是原型继承的优化方法
// 看到这个Object顺便追究一下Object这个万物(JS)之本

var obj  = Object({ name:"tcc"});//与加new等效
console.log(obj instanceof Object);//true
console.log(obj.name);//tcc

var ostr = Object("tcc");//Object构造函数也会像工厂方法一样,根据传入的值的类型返回相应的基本包装类型的实例
ostr.age = 18;
console.log(ostr instanceof String);//true
console.log(ostr.age);//18  可以存数据

var str = String("tcc");//这是转型函数,其它的还有Nmber()、 Boolean()、 Array()
var str = new String("tcc");//这是才是引用类型

你可能感兴趣的:(js,jQuery)