^ 异或 << 左移 >> 右移 delete 删除属性
toNumber对不一样的类型返回结果以下表数组
toPrimitive对不一样类型返回结果以下函数
function Book(title, pages) { this.title = title; this.pages = pages; } // 类申明函数有两种方法 Book.prototype.printTitle = function () { console.log(this.title) }; function Book(title, pages) { this.title = title; this.pages = pages; this.printTitle = function () { console.log(this.title) } } /** * 在原型上申明函数,只会建立一次,在全部实例中共享,能够节约内存和下降实例化的开销 * 在类定义中申明函数,每一个实例都会建立本身的函数副本 * * 原型上声明只能声明公共函数和属性 * 类定义中声明能够声明只能在类内部访问的私有函数和属性 */
function Book(title, pages) { this.title = title; this.pages = pages; } Book.prototype.printTitle = function () { console.log(this.title) }; // ES6语法 class Book { constructor(title, pages) { this.title = title; this.pages = pages; } printTitle() { console.log(this.title) }; } // 继承 class ITBook extends Book { constructor(title, pages, technology) { super(title, pages); this.technology = technology } printTechnology() { console.log(this.technology) } } // JavaScript的继承是基于原型实现的 // 使用属性存取器(get、set方法) class Person { constructor(name) { this._name = name } get name() { return this._name } set name(value) { this._name = value } } let Json = new Person('Json'); console.log(Json.name);// Json console.log(Json._name);// Json Json.name = 'Tom'; console.log(Json.name);// Tom Json._name = 'Jerry'; console.log(Json.name);// Jerry