jjzjj

Constructor

全部标签

javascript - 为什么更改原型(prototype)不会影响以前创建的对象?

我有以下代码:varA=function(){};vara=newA();varb=newA();A.prototype.member1=10;A.prototype={}varc=newA();console.log(a.member1);console.log(a.constructor===b.constructor);console.log(a.constructor===c.constructor);console.log('---------');console.log(c.member1);它的输出是:10truefalse---------undefinedundefi

javascript - NodeJS - 如何在自执行函数中将构造函数分配给 module.exports?

我正在尝试在NodeJS中的自执行函数中分配一个构造函数。我很确定它不起作用,因为我的参数是一个指向module.exports的变量,但我很好奇是否有办法让它工作,同时尽可能接近自执行格式。下面是代码的调用方式...varTemplateEngine=require('./templateEngine');templateEngine=newTemplateEngine({engine:'swig'});//"objectisnotafunction"这是一个运行良好的代码示例...varassert=require('assert');varswig=require('swig')

javascript - Javascript中构造对象的两种方式

functionPerson(age,name){this.name=name;this.age=age;this.speak=function(){...}}functionPerson(age,name){varp={}p.name=name;p.age=age;p.speak=function(){...}returnp;}我看到的唯一区别是,使用第一个你必须用new调用来让语言知道它正在构造一个新对象,它本质上只是构造一个对象,其中“this”指的是正在创建的新对象吗?即与这样做相同。{age:12,name:"mark",speak:function(){...}}第二个返回

javascript - 不要用 new Constructor 创建对象

是否可以选择不在构造函数中创建具有特定条件的对象,例如functionMonster(name,hp){if(hp 最佳答案 我认为你应该做的是抛出一个异常。functionMonster(name,hp){if(hp 关于javascript-不要用newConstructor创建对象,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/15355908/

javascript构造函数重置: What is it?

我看到这张幻灯片:http://www.slideshare.net/stoyan/javascript-patterns#postComment第35页:选项5+super+构造函数重置functioninherit(C,P){varF=function(){};F.prototype=P.prototype;C.prototype=newF();C.uber=P.prototype;C.prototype.constructor=C;//WHY???}我不明白。谁能解释一下最后一行是什么?C.prototype.constructor=C;//WHY???谢谢

javascript - 一个不涉及模拟经典继承的原型(prototype)继承的例子?

我阅读了以下QA,它们都检查了使用原型(prototype)继承来模拟经典继承。GoodExampleofJavaScript'sPrototype-BasedInheritancejavascriptinheritanceUsinginheritancepatternsinJavaScript在野外没有一个原型(prototype)继承的工作示例吗?也许是模拟生命形式?除了那些由编程语言创建或未充分解决的问题之外,还有哪些问题可以从原始原型(prototype)继承中受益? 最佳答案 继承就是继承,因此您可以从两者中获得相同的基本

javascript - 对 javascript 的构造函数和原型(prototype)感到困惑?

functionMyObject(){}Array.prototype={};MyObject.prototype={};vara=newArray();varb=newMyObject();alert(a.constructor==Array);//truealert(b.constructor==MyObject);//false 最佳答案 Array.prototype是一个不可写的属性。因此,您的作业:Array.prototype={}...没有成功,所以它的.constructor属性没有改变。15.4.3.1Array

javascript - 收到 "No parameterless constructor defined"错误,不确定原因

出于某种原因,我的一个特定AJAX调用出现“未定义无参数构造函数”错误。这是代码:CallAndReplace(JSON.stringify(model),url,$("#panel"));functionCallAndReplace(data,url,replace){$.ajax({url:url,type:"post",contentType:"application/json;charset=utf-8",data:data,success:function(result){replace.html(result);},error:function(x,e){if(x.stat

javascript - ES6 super() 在构造函数中实际上做了什么?

!你好,friend们。我有这个小类继承结构classPoint{constructor(x,y){this.x=x;this.y=y;}toString(){return'('+this.x+','+this.y+')';}}classColorPointextendsPoint{constructor(x,y,color){super(x,y);this.color=color;}toString(){returnsuper.toString()+'in'+this.color;}}letnewObj=newColorPoint(25,8,'green');它编译为thisjsfi

javascript - 如何修复 "TypeError: fsevents is not a constructor" react 错误

在使用npmstart启动React应用程序时发生此错误...我试过下面的东西:删除node_module包并重新安装使用yarn代替npm3.使用npm更新fsevent库仍然出现这个错误注意:如果我们创建React应用程序fresh/newyarnstart会工作,但我们关闭终端并使用以下相同的东西重新启动会发生以下错误/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:28return(newfsevents(path)).on('fsevent',callback).start();^Ty