首页 > 其他 > 详细

ES5 创建构造函数的私有属性

时间:2021-09-10 01:01:29      阅读:34      评论:0      收藏:0      [点我收藏+]

index.js

function Foo() {
  const list = [];
  this.push = function (val) {
    list.push(val);
  };
  this.getList = function () {
    console.log(list);
  };
}

const foo1 = new Foo();
const foo2 = new Foo();
foo1.push(1); 
foo1.getList(); // [ 1 ]
foo2.getList(); // []

ES5 创建构造函数的私有属性

原文:https://www.cnblogs.com/aisowe/p/15245929.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!