如果我有B类:A{}我说“B类继承A类”或“B类派生自A类”。但是,如果我有:classB:ISomeInterface{}说“B继承了ISomeInterface”是错误的——正确的说法是“B实现ISomeInterface”。但是,假设我有interfaceISomeInterface:ISomeOtherInterface{}现在,说“继承”仍然是错误的,但现在说“实现”也是错误的,因为ISomeInterface没有实现任何东西。那么,您如何称呼这种关系? 最佳答案 我个人说“扩展”,我认为C#规范也在某处使用了这个词(不幸
我最近在学习Node.js。我对Node.js中的函数util.inherits有疑问。我可以在CoffeeScript中使用extends来替换它吗?如果不是,它们之间有什么区别? 最佳答案 是的,您可以使用extends代替它。至于区别?让我们先来看看CoffeeScript:classBextendsA我们来看看theJavaScripttheCoffeeScriptcompilerproduces对于这个JavaScript:varB,__hasProp={}.hasOwnProperty,__extends=functio
我是node中的n00b,发现util.inherits()非常有用,除了它似乎替换了原始对象的整个原型(prototype)。例如:varmyClass=function(name){this._name=name;};myClass.prototype={(...)};util.inherits(myClass,require('events').EventEmitter);似乎抹去了我原来的原型(prototype)。这给我带来了两个不便:1-我必须在调用inherits,后向我的原型(prototype)声明添加属性varmyClass=function(name){this.
我在玩util.inheritsmethodfromnode.js并且似乎无法获得所需的行为。varutil=require("util");functionA(){this.name='old';}A.prototype.log=function(){console.log('myoldnameis:'+this.name);};functionB(){A.call(this);this.name='new';}util.inherits(B,A);B.prototype.log=function(){B.super_.prototype.log();console.log('myn