标签:js原型 OLE lang es6 prototype 定义函数 script name 添加
js定义函数:
<script>
function A() {}
let a1 = new A();
let a2 = new A();
// 为A类添加原型 => 类似于类属性
A.prototype.num = 100;
console.log(a1.num);
console.log(a2.num);
</script>
ES6语法下类
class B {
constructor(name) {
this.name = name;
}
}
let b1 = new B(‘Tom‘);
let b2 = new B(‘Ben‘);
B.prototype.count = 666;
console.log(b1.count);
console.log(b2.count);
console.log(b1.name);
console.log(b2.name);
标签:js原型 OLE lang es6 prototype 定义函数 script name 添加
原文地址:https://www.cnblogs.com/mqhpy/p/12069853.html