jjzjj

prototype-chain

全部标签

javascript - 变量隐式声明和原型(prototype)

尽量保持简短。使用phpstorm查看我的代码并发现了一些错误。它说我的函数命名位置有一个“隐式声明的变量”functiontowngate10(){updateDisplay(locations[10].description);if(!gate10){score=score+5;gate10=true;}playerLocation=10;displayScore();document.getElementById("goNorth").disabled=true;document.getElementById("goSouth").disabled=false;document.

javascript - 难以手动走原型(prototype)链

我想尝试手动遍历几个对象的原型(prototype)链,看看我在这个过程中找到了什么。但是,我卡在了我尝试的第一个上。这是代码:functionMyObject(){}varx=newMyObject();console.log('--------------------------------------------');console.log('x.constructor.name:'+x.constructor.name);console.log('x.constructor.prototype.constructor.name:'+x.constructor.prototype

javascript - 在javascript中将值设置为__proto_ _` and `原型(prototype)

这个问题在这里已经有了答案:__proto__VS.prototypeinJavaScript(34个答案)关闭6年前。__proto__和prototype有什么区别我看了网上的大部分文章,还是看不懂..据我所理解__proto__是原型(prototype)对象的属性prototype是实际的对象我对么?....为什么只有函数才有原型(prototype)属性?它如何成为一个对象?varfn=function(){};console.dir(fn);输出functionfn()arguments:nullcaller:nulllength:0name:""prototype:Obj

javascript - 为什么在 Javascript 中属性写入不引用原型(prototype)链?

我已经盯着这个答案看了一段时间,但我无法理解它:https://stackoverflow.com/a/23699009/3658800.总结:只有属性读取搜索原型(prototype)链,而不是写入。所以当你设置myObject.prop='123';它不查找链,但是当你设置myObject.myThing.prop='123';在那个写操作中有一个微妙的读操作,它试图在写入它的prop之前查找myThing。这就是为什么从子对象写入object.properties会得到父对象的原因。我基本上是在要求某人详细说明这个“微妙的阅读”操作。myObject.myThing是否首先求值,

javascript - 如何在支持 tree shaking 的同时使用 `chain` 和 `lodash-es`?

众所周知,lodash-es使用更模块化的语法构建,以通过构建工具支持treeshaking。但是,chain相关的功能意味着一些功能附加到对象/原型(prototype)链。我可以看到chain是用lodash-es发布的,但我不确定如何通过其他链接方法正确导入它。用例可能如下所示:import{chain}from'lodash-es'exportfunctiondouble(input){returnchain(input).without(null).map(val=>val*2).value().join(',')}编辑#1:重点不在于如何导入chain,而在于如何导入其他c

Javascript 原型(prototype)语法

这是有效的Javascript语法吗?它有什么作用?Parser.prototype={//...getcurrentState(){returnthis.state[this.state.length-1];},//...}参见https://github.com/LearnBoost/stylus/blob/master/lib/parser.js.谢谢! 最佳答案 它定义了一个getter:Bindsanobjectpropertytoafunctionthatwillbecalledwhenthatpropertyisloo

javascript - 为什么 prototyping Function 不影响 console.log?

我制作了Function原型(prototype),使其具有getBody函数:Function.prototype.getBody=function(){//Getcontentbetweenfirst{andlast}varm=this.toString().match(/\{([\s\S]*)\}/m)[1];//Stripcommentsreturnm.replace(/^\s*\/\/.*$/mg,'');};参见here获取更多信息。我试过这样测试:console.log(console.log.getBody.getBody());但收到错误:TypeError:cons

javascript - IE8 Array.prototype.slice : 'this' is not a JavaScript object

我只在IE8中收到此错误消息,我不知道如何转换现有函数以兼容IE8。_initEvents:function(){varself=this;Array.prototype.slice.call(this.menuItems).forEach(function(el,i){vartrigger=el.querySelector('a');if(self.touch){trigger.addEventListener('touchstart',function(ev){self._openMenu(this,ev);});}else{trigger.addEventListener('cl

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 - 构造函数中的 "use strict"是否扩展到原型(prototype)方法?

我试图弄清楚“usestrict”的定义是否扩展到构造函数的原型(prototype)方法。示例:varMyNamespace=MyNamespace||{};MyNamespace.Page=function(){"usestrict";};MyNamespace.Page.prototype={fetch:function(){//doIneedtouse"usestrict"hereagain?}};根据Mozilla您可以将其用作:functionstrict(){"usestrict";functionnested(){return"AndsoamI!";}return"Hi