草庐IT

c++ - 不明确的类继承

全部标签

javascript - 原型(prototype)继承的差异,Firefox 与 Chrome

对于下面的代码:functionMammal(){this.hair=true;this.backbone=true;returnthis;}functionCanine(){this.sound='woof';returnthis;}Canine.prototype=newMammal();functionDog(name){this.tail=true;this.name=name;returnthis;}Dog.prototype=newCanine();varaspen=newDog('Aspen');varaspenProto=aspen.__proto__Firebug(F

javascript - Webpack 在使用继承缩小/丑化 ES6 代码时删除了类名

Webpack在使用继承缩小/丑化ES6代码时删除了类名:有MVCE我们尝试缩小/丑化的代码:子类:constParentClass=require('parent');classChildextendsParentClass{constructor(){super();}}module.exports=Child;index.js调用Child类:constChild=require('./classes_so/child');letchild=newChild();console.log(child.constructor.name);node_modules中的ModulePar

javascript - 为什么 console.log() 不显示从 Object.create 继承的属性?

我在尝试利用基础对象上的Object.defineProperty()时遇到了问题。我想使用Object.create()从该对象继承属性,然后在派生对象(可能从那里继承)中定义更多属性。我应该指出,我的目标是node.js。这是一个例子:varBase={};Object.defineProperty(Base,'prop1',{enumerable:true,get:function(){return'prop1value';}});Object.defineProperty(Base,'prop2',{enumerable:true,value:'prop2value'});Ob

javascript - Javascript 中的继承

我正在研究Javascript中的继承概念,我正在看的教程使用了这段代码://definetheStudentclassfunctionStudent(){//CalltheparentconstructorPerson.call(this);}//inheritPersonStudent.prototype=newPerson();//correcttheconstructorpointerbecauseitpointstoPersonStudent.prototype.constructor=Student;我的问题是,为什么有必要同时调用父构造函数Person.call(this

javascript - 从 native 对象继承

我似乎遗漏了一些关于Javascript中使用native对象的构造函数链继承的信息。例如:functionErrorChild(message){Error.call(this,message);}ErrorChild.prototype=Object.create(Error.prototype);varmyerror=newErrorChild("Help!");为什么myerror.message在这些语句之后被定义为""?我希望Error构造函数将其定义为“帮助!”(并覆盖Error.prototype.message的默认值),就像我在做的那样:varmyerror=new

javascript - 覆盖继承的原型(prototype)方法并在新方法中调用原始方法

在下面的代码中,如何访问B.prototype.log中的A.prototype.log?functionA(){}A.prototype.log=function(){console.log("A");};functionB(){}B.prototype=Object.create(A.prototype);B.prototype.constructor=B;B.prototype.log=function(){//callA.prototype.loghereconsole.log("B");};varb=newB();b.log();我知道我可以只写A.prototype.log

javascript原型(prototype)继承和对象属性

我正在尝试将原型(prototype)继承应用于Javascript中的函数。这一切都非常简单,甚至在Wikipedia'sjavascriptlemma中进行了描述.如果我的属性是简单的javascript类型,它就可以工作:functionPerson(){this.age=0;this.location={x:0,y:0,absolute:false};};functionEmployee(){};Employee.prototype=newPerson();Employee.prototype.celebrate=function(){this.age++;}varpete=n

javascript - 原型(prototype)继承: Can you chain Object.创建?

我是原型(prototype)继承的新手,所以我想了解“正确”的方式。我以为我可以这样做:if(typeofObject.create!=='function'){Object.create=function(o){functionF(){}F.prototype=o;returnnewF();};}vartbase={};tbase.Tdata=functionTdata(){};tbase.Tdata.prototype.say=function(data){console.log(data);};vartData=newtbase.Tdata();tbase.BicData=Ob

javascript - 你如何在 JavaScript 中进行继承而不在子类的所有实例之间共享父类(super class)的同一个实例?

我注意到每个关于如何进行JavaScript继承的教程都是这样做的:SubClass.prototype=newSuperClass();但这将创建父类(superclass)的单个实例并在子类的所有实例之间共享它。问题是我想将参数传递给父类(superclass)构造函数,这些构造函数源自传递给子类的参数。在Java中,这将像这样完成:classSubClassextendsSuperClass{publicSubClass(Strings){super(s);}}我试过这样做:functionSubClass(args){this.constructor.prototype=new

javascript - 如何使用 Javascript 获取继承的 CSS 值?

我正在尝试使用Javascript获取继承的CSS属性的值。我一直没能找到全面的答案。示例CSS:div{width:80%;}示例标记:Sometext使用javascript(jQuery或native),我需要获取元素的宽度——不是以像素为单位,而是字符串“80%”。$('#mydiv').css('width');//returnsinpx$('#mydiv')[0].style.width//emptystringgetComputedStyle($('#mydiv')[0]).width//returnsinpx我需要将值作为字符串的原因是因为我需要将样式复制到另一个元素。