要创建 Person 的新实例,必须使用 new 操作符.以这种方式调用构造函数实际上会经历以下 4个步骤:(1) 创建一个新对象:(2) 将构造函数的作用域赋给新对象(因此 this 就指向了这个新对象) :(3) 执行构造函数中的代码(为这个新对象添加属性) :(4) 返回新对象. new 操作符 在有上面的基础概念的介绍之后,在加上new操作符,我们就能完成传统面向对象的class + new的方式创建对象,在JavaScript中,我们将这类方式成为Pseudoclassical.基于上
js中的5中基本数据类型 js标识符 第一个字符必须为字母,下划线,或美元符 其他字符可以是字母,下划线,美元符,数字 js标识符区分大小写 标识符不能使关键字和保留字 关键字: break do instanceof typeof case else new var catch finally return void continue for switch while debugger function this with default if throw delete in try
new 操作符做了以下事情: 1.创建一个对象,将对象赋值给this function Person(name, age) { console.log(this) //Person {} } let p = new Person('cj', 24) 2.执行构造函数的代码,将构造器中的this.prop属性添加到this上 function Person(name, age) { console.log(this) //Person {} this.name = name this.age =
JavaScript中不能作为变量名的关键字和保留字总结: 1.js中的关键字: break case catch continue default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with 2.js中的保留字: abstract boolean byte char class const debugger dou