草庐IT

Prototype

全部标签

javascript - 原型(prototype)继承,为什么是实例而不是原型(prototype)?

自从我了解原型(prototype)继承以来,我一直想知道为什么将父类的实例而不是原型(prototype)本身推送到子原型(prototype)中?varAnimal=function(type){this.type=type;}Animal.prototype.getType=function(){returnthis.type;}varCat=function(options){this.breed=options.breed;}//InheritanceCat.prototype=newAnimal('Cat');为什么不这样继承呢?Cat.prototype=Animal.p

javascript - 为继承复制原型(prototype)?

我一直在玩JavaScript,特别是用类和诸如此类的东西模拟面向对象的编程。我知道这种实现继承的方式MyClass.prototype=newAnotherClass();但我并不满意,我不喜欢我需要如何调用AnotherClass的构造函数。所以我一直在玩,想出了一些似乎有效的东西,基本上想要第二个意见。functionclone(obj){functionCloneFactory(){}CloneFactory.prototype=obj;returnnewCloneFactory();}MyClass.prototype=clone(AnotherClass.prototype

javascript - javascript 中的特性

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭8年前。Improvethisquestion如何在javascript中实现特征?

javascript - 一个 JavaScript 对象可以有一个原型(prototype)链,同时也是一个函数吗?

functiona(){return"foo";}a.b=function(){return"bar";}functionc(){};c.prototype=a;vard=newc();d.b();//returns"bar"d();//throwsexception,disnotafunction有没有办法让d成为一个函数,同时仍然继承a的属性? 最佳答案 实际上,事实证明这是可能的,尽管是以非标准的方式。Mozilla、Webkit、Blink/V8、Rhino和ActionScript提供了一个非标准的__proto__属性,

javascript - [].slice 或 Array.prototype.slice

我遇到过两种将数组原型(prototype)应用于native对象的方法:arr=Array.prototype.slice.call(obj);arr=[].slice.call(obj);以类似的方式,获取原生类数组对象的真实类型:type=Object.prototype.toString.call(obj);type={}.toString.call(obj);一个简单的测试:functionfn(){console.log(Array.prototype.slice.call(arguments),[].slice.call(arguments),Object.prototy

javascript - 这比。原型(prototype)

这个问题在这里已经有了答案:Useof'prototype'vs.'this'inJavaScript?(15个答案)关闭8年前。将方法“area”定义为“this”而不是“prototype”的属性有什么区别?//console.clear()functionRectangle(w,h){this.width=w;this.height=h;this.area=function(){returnthis.width*this.height;}}varr=newRectangle(2,3);vara=r.area();//console.log(a)functionSquare(s){

javascript - javascript中原型(prototype)的含义

我写了从Person继承reader的简短代码:/*ClassPerson.*/functionPerson(name){this.name=name;}Person.prototype.getName=function(){returnthis.name;}varreader=newPerson('JohnSmith');alert(reader.getName());或者我可以删除Person.prototype.getName=function(){returnthis.name;行}并在Person对象中创建它。例如/*ClassPerson.*/functionPerson(

javascript - jQuery closest 函数的原型(prototype)等价物

对于jQueryclosest函数,Prototype中是否有任何等价物?http://api.jquery.com/closest/谢谢 最佳答案 您可以使用up方法。它并不完全等价,因为closest也考虑了当前元素。所以你需要先测试你选择的元素,看看它是否符合你的标准,如果不符合,使用up-method:jQuery:return$('#id').closest('li');Prototype:varelement=$('id')returnelement.match('li')?element:element.up('li'

php - 如何在 php 中使用 JS 原型(prototype)从 Select html 元素中检索值?

functionreload(form){varval=$("seltab");alert(val);}echo"";echo"";$querysel="SELECTtitle_id,authorFROMauthorsNATURALJOINbooks";$result1=mysql_query($querysel);while($rowID=mysql_fetch_assoc($result1)){$TitleID=$rowID['title_id'];$author=$rowID['author'];print"$author\n";print"";}print"";

php - 自定义数据类型类

我正在考虑为我正在进行的项目制作自定义数据类型/原型(prototype),但我想知道这是否是个好主意?例如classString{var$Value;private$escaped=false;function__construct($String){$this->Value=$String;}functionescape(){if($escaped===false){$this->Value=Registry::get('Database')->escape($this->Value);}return$this;}functiontrim(){$this->Value=trim($