如何在构造函数中访问类变量?(node . js OOP)
How to access class variables in the constructor? (node.js OOP)
是否有某种方法可以访问构造函数中的类变量?
var Parent = function() {
console.log(Parent.name);
};
Parent.name = 'parent';
var Child = function() {
Parent.apply(this, arguments);
}
require('util').inherits(Child, Parent);
Child.name = 'child';
。e父类的构造函数应该记录"父",子类的构造函数应该记录基于每个类的某个类变量的"子"。
这是在香草js:
var Parent = function() {
console.log(this.name);
};
Parent.prototype.name = 'parent';
var Child = function() {
Parent.apply(this, arguments);
}
Child.prototype = new Parent();
Child.prototype.constructor = Child;
Child.prototype.name = 'child';
var parent = new Parent();
var child = new Child();
跑龙套。继承只是简化了
Child.prototype = new Parent();
Child.prototype.constructor = Child;
到
util.inherits(Child, Parent);
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- 如何使用 node.js 比较两个 json 数组
- Node.js's Buffer.writeFloatBE in Javascript
- node.js:setInterval()正在跳过调用
- 如何处理node.js节点mongodb中的连接和查询队列
- Node.js正在更改应用程序以使用集群模块
- 如何使用Node.js最有效地解析网页
- 在openshift node js应用程序中获取请求
- 正在删除node.js中已验证的网站
- 与运行长作业(javascript,node.js)的第三方API同步的最佳实践
- 在索引.html和应用.js [node.js] 之间共享变量
- Node.js中的JavaScript原型对象效率
- node.js请求数据事件未在CORS ajax调用中触发
- 使用node.js制作网站
- 使用node.js服务器中的evernote api获取note内容
- 有没有任何方法可以使用node-js从不同的机器打开浏览器
- 使用CI和CodeDeploy对node.js应用程序进行连续部署
- 在Node.js中上传和检索图像
- 什么's本地node.js服务器和python简单http服务器之间的区别
- 如何使用 Node JS 获取 JSON 嵌套数组值