脚本宝典收集整理的这篇文章主要介绍了《JavaScript数据结构与算法》笔记——第1章 JavaScript简介,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
^ 异或
<< 左移
>> 右移
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
以上是脚本宝典为你收集整理的《JavaScript数据结构与算法》笔记——第1章 JavaScript简介全部内容,希望文章能够帮你解决《JavaScript数据结构与算法》笔记——第1章 JavaScript简介所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。