instanceof与typeof

都会返回类型信息,但installedof与内存中的比较typeof与字符串比较

//objects
  var Person = function() {}

  var gary = new Person();

  console.log(typeof(gary)); // "object"
  gary instanceof Person // true

  //literals
  var str = 'hello world';
  console.log(typeof(str)); // "string"
  str instanceof String // False

  var str1 = new String('hello world');
  console.log(typeof(str1)) // "object"
  str1 instanceof String // true 

  

posted @ 2015-06-02 08:09  夏棋  阅读(212)  评论(0编辑  收藏  举报