Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

06-13 数据类型 #8

Open
hanfengmi opened this issue Jun 13, 2019 · 0 comments
Open

06-13 数据类型 #8

hanfengmi opened this issue Jun 13, 2019 · 0 comments

Comments

@hanfengmi
Copy link
Owner

hanfengmi commented Jun 13, 2019

1.数据类型

  • 基本数据类型

Number,String,Boolean,Undefined,Null

  • 复杂数据类型

Object

  • ES6

Symol对象属性名都是字符串容易造成属性名冲突。为了避免这种情况的发生,ES6引入了一种新的原始数据类型Symbol,表示独一无二的值.

判断数据类型

  • typeof
typeof ''; // string 有效
typeof 1; // number 有效
typeof Symbol(); // symbol 有效
typeof true; //boolean 有效
typeof undefined; //undefined 有效
typeof null; //object           !!**无效**
typeof [] ; //object             !!**无效**
typeof new Function(); // function 有效
typeof new Date(); //object           !!**无效**
typeof new RegExp(); //object      !!**无效**
  • instanceof

instanceof 只能用来判断两个对象是否属于实例关系, 而不能判断一个对象实例具体属于哪种类型

[] instanceof Object  // true
{} instanceof Object  // true
  • toString
    对于 Object 对象,直接调用 toString() 就能返回 [object Object] 。而对于其他对象,则需要通过 call / apply 来调用才能返回正确的类型信息。
Object.prototype.toString.call('') ;   // [object String]
Object.prototype.toString.call(1) ;    // [object Number]
Object.prototype.toString.call(true) ; // [object Boolean]
Object.prototype.toString.call(Symbol()); //[object Symbol]
Object.prototype.toString.call(undefined) ; // [object Undefined]
Object.prototype.toString.call(null) ; // [object Null]
Object.prototype.toString.call(new Function()) ; // [object Function]
Object.prototype.toString.call(new Date()) ; // [object Date]
Object.prototype.toString.call([]) ; // [object Array]
Object.prototype.toString.call(new RegExp()) ; // [object RegExp]
Object.prototype.toString.call(new Error()) ; // [object Error]
Object.prototype.toString.call(document) ; // [object HTMLDocument]
Object.prototype.toString.call(window) ; //[object global] window 是全局对象 global 的引用

2. 原型、原型链、继承、构造函数、实例

@hanfengmi hanfengmi changed the title 06-13 数据类型、原型、继承、作用域、arguments 06-13 数据类型 Jun 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant