草庐IT

data-prototype

全部标签

Javascript:沿着原型(prototype)链传递构造函数参数。有办法吗?

在下面的示例中,是否有一种方法可以构造对象,使“b”具有属性a1,并初始化为“2”?functionA(a1){this.a1=a1;}functionB(b1,a1){this.b1=b1;}B.prototype=newA;varb=newB('1','2');我基本上是在尝试在传统的面向对象语言(例如C#)中复制所谓的“调用基本构造函数”。 最佳答案 像这样?functionB(b1,a1){A.call(this,a1);this.b1=b1;} 关于Javascript:沿着原

javascript - 为什么控制台会注意到我在更改原型(prototype)之前更改了原型(prototype)?

我正在学习Javascript原型(prototype)并用这个javascript制作了一个Fiddle(http://jsfiddle.net/3MuZa/1/):functionAnimal(name,sound){this.name=name;this.sound=sound;}vardog=newAnimal("Dog","Bark");console.debug(dog.__proto__);Animal.prototype.makeSound=function(){console.log(this.sound);};有趣的是,console.debug(dog.__pro

javascript - Object.create( Class.prototype ) 在这段代码中做了什么?

我正在阅读mixinpatterninjavascript我遇到了这段我不理解的代码:SuperHero.prototype=Object.create(Person.prototype);原代码中实际上有一个错字(大写的H)。如果我小写它就可以了。但是,如果我真的删除该行,一切似乎都一样。完整代码如下:varPerson=function(firstName,lastName){this.firstName=firstName;this.lastName=lastName;this.gender="male";};//anewinstanceofPersoncantheneasily

javascript websocket onmessage event.data

使用JavaScriptWebSocket如何将event.data传出onMessage函数?vareventData=EventRequest("text");.....codes.....EventRequest=function(text){varsocket=newWebSocket('ws://localhost:8080/');websocket.onopen=function(evt){onOpen(evt);};websocket.onmessage=function(evt){onMessage(evt);};functiononOpen(evt){socket.s

javascript - 如何使用 Gulp 和 gulp-data 从单个 jade 模板生成多个 html 文件

我正在使用Gulp创建一个静态站点生成器.我想知道如何将每条数据(JSON)通过管道传输到一个jade模板中以生成多个html文件。这是gulp的"template"任务:gulp.task('templates',function(){'usestrict';varmyData=JSON.parse(fs.readFileSync('./_assets/data/content.json'));varmyPages=myData.pages;varmyPosts=myData.posts;gulp.src('./_assets/templates/index.jade').pipe(

javascript - 相当于 Array.prototype.map() 的 Dart?

我尝试从Dart中的map列表中获取ID。在JavaScript中会是这样的:varlist=[{id:3,name:'third'},{id:4,name:'fourth'}];varresult=list.map(function(x){returnx.id;});这应该给出结果[3,4]在Dart中是否有一种简单的方法可以做到这一点?到目前为止,我能够做到这一点(在Dart中):varlist=[{'id':3,'name':'third'},{'id':4,'name':'fourth'}];varresult=list.map((x)=>x['id']);结果是“Mapped

javascript - 如何获取通过 sails.js 中的表单发送的数组/对象(使用 enctype multipart/form-data)

我在我的表单中嵌套信息以匹配我的模型,这极大地简化了后端的事情,但我无法找到如何在Sails.js中获取数组或对象(或两者的组合)假设我有这样的表格注意:完全需要支持“multipart/form-data”。我希望在req.params.all()obj中得到这样的对象{status:'published',entries:[{title:'Entry1',content:'Entry1Content...'},{title:'Entry2',content:'Entry2Content...'}]}现在调用req.params.all()/req.body时,我得到的是:{stat

Javascript : Modifying Prototype doesn't affect existing Instances

这个问题在这里已经有了答案:OverwritingandExtendingPrototype(1个回答)关闭5年前。我创建了原型(prototype)的2个实例,更改了原型(prototype)中的函数,更改反射(reflect)在两个实例中(很棒)。但是,当我通过删除该函数修改原型(prototype)时,该函数对于现有实例仍然存在。functionA(){this.name="cool";}A.prototype={howCool:function(){returnthis.name+"er";}};vara1=newA(),a2=newA();a1.name="hot";//li

javascript - jQuery 与 Prototype 的 Ajax.Responders.register 的等价物是什么?

是否有与此原型(prototype)代码等效的jQuery?Ajax.Responders.register({onException:function(x,y){if(y.message!="Syntaxerror")newInsertion.After("toperrorbox",""+y.message+"");}}); 最佳答案 Prototype的Ajax.Responders是监听所有ajax事件的全局监听器。jQuery确实有一个等价物。全局AjaxEvents.由于jQuery的性质,语法略有不同,但与此类似的东西应

javascript - 什么是 JavaScript 中的原型(prototype)?

什么是JavaScript类的原型(prototype)?换句话说,有什么区别Example.prototype.method{}和Example.method{}在定义Example类时?编辑:对于那些感兴趣的人,我在这里找到了关于类方法和构造方法之间区别的很好的解释(除了下面的答案):http://idhana.com/2009/07/13/constructor-vs-class-methods-in-javascript/编辑2:完整答案!http://blog.anselmbradford.com/2009/04/09/object-oriented-javascript-t