草庐IT

revealing-prototype

全部标签

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 原型(prototype)语法

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

Javascript Revealing Module 模式 - 在函数返回后公开初始化变量

我一直在大量使用JavascriptRevealingModule模式,我喜欢它在公共(public)接口(interface)和内部之间的清晰分离。然而,我一直遇到这样一种情况,这让我想知道我的整体使用模式是否正确,或者我是否应该使用该模式的一些变体。问题在于,当传递到模块的init函数中并私下存储供内部使用的某些内容也需要在Knockout绑定(bind)表达式或其他模块中公开时。模块的返回语句立即执行,稍后调用init函数,通常传递一些动态参数,例如AjaxURL或在RazorView中的脚本block中呈现的原始JSON。因为模块的return语句只返回私有(private)变

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