草庐IT

generic-function

全部标签

JavaScript 模式 : Context of Function Call

从一开始我就有大量的JavaScript,函数调用是这样写的:THING.someFunction.call(THING);在我看来,它应该始终等同于:THING.someFunction();这两个调用总是等价的吗?旧版本的JavaScript呢?在我看来,第一行代码中第二个THING的目的是在someFunction中设置上下文(this).但是默认情况下,该函数内的上下文应该已经是THING了,对吧?为了清楚起见,THING的定义如下:varTHING=function(){//privatevarsreturn{//codesomeFunction:function(){//c

javascript - 我不断收到 TypeError : undefined is not a function

在MEAN堆栈应用程序中运行以下代码时,我不断收到上述错误:$scope.completelesson=function(lessonindex,type){//avariablethatwillbeappendedto'level'inordertoaccessthelevelpropertyoftheuservarx=lessonindex+1;varlevel='level'+x;vartoupdate={level:level,type:type,};console.log(toupdate);$http({method:'POST',url:'/users/updatelev

javascript - 良好做法 : How can I ensure a JavaScript constructor has access to mixin functions?

作为RPG游戏后端的一部分,我希望能够对Angular色应用临时效果。这些影响的性质可能有很大差异,但我想保持定义它们的方法非常简单。我将自定义事件处理用作混合:varEvtObject={};$rpg.Event.enable(EvtObject);//Addthe3methodsandsetEvtObject._events={}我想将Auras(临时效果)定义为带有事件处理代码的构造函数:varMyAura=function(any,args){this.group="classification";this.on("tick",function(){});this.on("re

javascript - 为什么在 Firefox 中 Function.prototype.func=... 不影响 console.log?

我已经使用Function.prototype.func=...添加了一个函数到Function但在Firefox中它没有被添加console.log:Function.prototype.func=function(){returnthis.toString();};alert(typeofconsole.log.func);//inFF:undefined,inChrome:function这是错误还是有任何原因? 最佳答案 在Firefox中很明显:varfoo=function(){}foo.__proto__==Funct

javascript - 为什么 Closure 在使用 function.apply 时不对参数进行类型检查?

见下文/***@param{string}a*@param{string}b*/varf=function(a,b){//...}/***@param{string}a*@param{boolean}c*/varh=function(a,c){f.apply(this,arguments);//nocompileerrorf.apply(this,[a,c]);//nocompileerrorf.call(this,a,c);//compileerror:doesnotmatchformalparameter}为什么Closure只在使用call而不是apply时报错?有没有一种方法可

javascript - TypeError : str. replace is not a function strange error with vue.js Ajax 调用

我收到一个奇怪的错误:vue-resource.common.jsUncaughtTypeError:str.replaceisnotafunction它似乎与我正在获取一些的ajax调用有关数据:exportdefault{data:()=>({recipes:[]}),ready(){this.$http.get('http://localhost:3000/recipes',{headers:{'Access-Control-Allow-Origin':true}}).then((recipes)=>{this.$set('recipes',recipes)})}};我是vue.

javascript - 是什么导致 TypeError : Expected `input` to be a `Function` or `Object` issue with gtoken and pify?

我正在尝试将FirebaseRemoteConfig集成到我的Cordova应用程序中,以强制用户在拥有最低版本时进行更新,但导入包会导致错误。它不能在代码中,因为错误是在代码运行之前抛出的,只是通过导入包。TypeError:Expected`input`tobea`Function`or`Object`,got`undefined`at./node_modules/gtoken/node_modules/pify/index.js.module.exports(index.js:45)atObject../node_modules/gtoken/build/src/index.js

javascript - ES6 : Re-defining exported function

给定一个导出函数并在其内部逻辑中使用该函数的第3方库-是否有任何方法可以重新定义该函数?例如:third-party.jsexportfunctiona(){console.log('a');}exportfunctionb(){a();}我的模块.jsimport*astpfrom'third-party';//Re-define,somethinglikethisObject.defineProperty(tp,'a',{writable:true,value:()=>console.log('c')});//Callbandgetthere-definefunctioncalle

javascript - map : trigger a function on 'select'

这是我试图在我的网站上实现的地理图表map的代码:google.load('visualization','1',{'packages':['geochart']});google.setOnLoadCallback(drawRegionsMap);functiondrawRegionsMap(){vardata=google.visualization.arrayToDataTable([['Country'],['Italy'],['Germany'],['France'],['Turkey'],['Indonesia']]);varoptions={};varchart=newg

javascript - JavaScript 中 Number 和 Function.prototype 之间的关系是什么?

我正在阅读Javascript:theGoodParts这本书。当我阅读下面的代码时,我有点困惑:Function.prototype.method=function(name,func){this.prototype[name]=func;returnthis;};Number.method('integer',function(){returnMath[this我认为上面代码的第一部分意味着JavaScript中的任何函数现在都有一个名为method的方法。但是“数字”也是一个函数吗?为什么Number.method有意义?我假设Number继承了Number.prototype,