草庐IT

undefined-reference

全部标签

javascript - Backbone : Correct way of passing 'this' reference to anon functions in success/error callbacks

给定下面的主干View函数,将this(即当前View)传递给回调中定义的匿名函数的正确方法是什么?addSomething:function(e){varnewSomething=this.model.somethings.create({someProperty:xxx},{success:function(m,response){this.doSomething();//***HERE****},error:function(m,response){//Error}});},没有和变化,anon函数中的this设置为window。我可以这样设置一个引用:varthisView=t

javascript - 在 if 语句中使用 undefined variable

此代码段导致JavaScript运行时错误:(foo未定义)if(foo){//...}我必须先定义foo,如下所示:varfoo=foo||null//orundefined,0,etc....只有这样我才能做:if(foo){//...}这是为什么呢?更新:这对我来说有点脑残:“当然你不能访问未分配的变量。”有趣的是,你可以对undefinedvariable执行typeof()。我要接受miccet的答案,因为我认为这是最优雅的解决方案。 最佳答案 我感觉到你在问,因为你知道javascript似乎在某些情况下(即没有运行时错

javascript - JSLint 忽略 undefined variable

为了开发,我把我的js程序切碎成很多block。现在,当我通过JSLint运行一个片段时,我得到了很多类型的错误:Problematline48character42:'XXXXXXX'wasusedbeforeitwasdefined.我一直在寻找一个选项“容忍undefinedvariable”,但没有找到任何这样的选项。我该怎么做才能让JSLint忽略undefinedvariable? 最佳答案 来自JSLintdocumentation:JSLintalsorecognizesa/*global*/directivetha

javascript - 自定义过滤器在 AngularJS 中给出 "Cannot read property ' 切片' of undefined"

我的自定义startFrom过滤器给我一个错误。app.filter('startFrom',function(){returnfunction(input,start){start=+start;//parsetointreturninput.slice(start);}});app.controller("PostCtrl",function($scope,$http){$scope.currentPage=0;$scope.pageSize=10;$scope.hidePagination=true;$scope.search=function(){$http.get('some

javascript - this.userId 在 Meteor.publish 中返回 undefined

在我的一个Meteor.publish()函数中,this.userId的值为undefined。我不能调用Meteor.userId()因为它是notavailableinsideapublishfunction.你现在应该如何获得userId? 最佳答案 有四种可能:没有用户登录。您正在从服务器调用该方法,因此没有用户与该调用关联(除非您是从另一个具有用户绑定(bind)的函数调用它到它的环境,比如另一种方法或订阅函数)。你甚至没有accounts-base安装包(或任何附加组件)。我只是为了完整性才包括这个。您正在使用ES6中

javascript - window.undefined = window.undefined 有什么意义

我正在查看过去版本的jQuery代码,似乎在每个版本中theyhavethislineofcode里面的某个地方:window.undefined=window.undefined;我不明白为什么这很重要,更重要的是,它有什么作用。这似乎是将undefined分配给undefined,这对我来说毫无意义。但这似乎很重要,我对此很好奇。 最佳答案 window.undefined并不总是存在,所以像if(foo===undefined)这样的代码会在旧版浏览器中抛出ReferenceError,因为undefined未定义(即未声明)

javascript - void(0) 返回 `undefined` ,但允许属性访问。为什么?

因此void在执行传递给它的表达式后返回undefined。undefined在您尝试访问其属性时抛出异常。那么为什么void(0).prop返回undefined而不是崩溃?alert("void(0)=>"+void(0));//undefined//Howisitthatthisdoesn'tthrowanexception?alert("void(0).someprop=>"+void(0).someprop);//undefined//Exception,can'taccesspropertyofundefined.alert("undefined.someprop=>"+u

javascript - 您必须将组件传递给 connect 返回的函数。而是收到了 undefined

下面的代码给出了UncaughtError:Youmustpassacomponenttothefunctionreturnedbyconnect.InsteadreceivedundefinedList.jsimportReactfrom'react';import{connect,bindActionCreators}from'react-redux';importPostListfrom'../components/PostList';//ComponentIwishtowrapwithactionsandstateimportpostListfrom'../Actions/Po

javascript - 未捕获的类型错误 : Undefined is not a function on indexOf

我目前有这段代码来检查特定ID的网站URLGET选项,但是每当运行这段代码时,我都会收到一个奇怪的错误:UncaughtTypeError:Undefinedisnotafunction这是我的代码:varfamilyid="id=8978566";varcorporateid="id=8978565";if(window.location.indexOf(familyid)===-1){document.write("FamilyIDnotfound");}如果我能在这个问题上得到一些指导,那就太棒了......我无法使用.indexOf()函数找到类似的问题

javascript - JavaScript 函数中名为 "undefined"的参数的用途是什么?

在查看jQuery的未压缩源代码时,我偶然发现了一些我不太理解的东西。当创建他们的匿名函数时,他们将undefined作为第二个参数。这是在做什么,为什么他们使用undefined?是否有必要将undefined作为匿名函数的参数?下面是我正在谈论的示例。(function(window,undefined){...codehere})(window); 最佳答案 它所做的是在闭包内将undefined重新分配给undefined。那是一个故障保险。因为其他代码可能会不小心做类似的事情undefined=something;cons