js原型补充
2024-09-29 17:10:11
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);
最新文章
- JAVA中的Fork/Join框架
- resin 安装配置
- 【LeetCode OJ】Construct Binary Tree from Preorder and Inorder Traversal
- centos 7.0 菜鸟接触命令 记录
- C语言基础--for循环
- Rebar:Erlang构建工具
- IIS短文件名泄露漏洞危害及防范方法
- 自己用的一个ASP.Net MVC分页拿出来分享下(转)
- RequireJS示例
- flash 类和对象的关系
- IIS7.5 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。=
- 解决cors跨域的filter
- window7环境下ZooKeeper的安装及运行
- WinForm界面设计-Button添加背景图去边框
- oracle经验记录
- lambda 表达式拼接
- 前端框架VUE----node.js的简单介绍
- oepnni安装
- swift学习之Label
- python 获取网页编码格式