《JavaScript數據結構與算法》筆記——第1章 JavaScript簡介

^     異或
<<    左移
>>    右移
delete    刪除屬性
  • 不一樣類型之間「==」比較

不一樣類型之間「==」比較

  • ===在比較對象時,比較的是引用
  • toNumber和toPimitive是內部方法

toNumber對不一樣的類型返回結果以下表
toNumber對不一樣的類型返回結果以下表數組

toPrimitive對不一樣類型返回結果以下
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)
    }
}
/**
* 在原型上申明函數,只會建立一次,在全部實例中共享,能夠節約內存和下降實例化的開銷
* 在類定義中申明函數,每一個實例都會建立本身的函數副本
*
* 原型上聲明只能聲明公共函數和屬性
* 類定義中聲明能夠聲明只能在類內部訪問的私有函數和屬性
*/
  • ES6函數參數默認值
  • 聲明展開和剩餘參數
  • 數組結構
  • 變量互換
  • 屬性簡寫
  • ES6的類聲明方式
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
相關文章
相關標籤/搜索