草庐IT

Variable_name

全部标签

Javascript 继承 : Parent's array variable retains value

我在这里尝试在JavaScript中使用继承,我发现Parent类中的数组值被Child类继承时出现问题。下面的代码是正常的继承:varParent=function(){this.list=[];};varChild=function(){};Child.prototype=newParent;Child.prototype.constructor=Child;varobj1=newChild;obj1.list.push("hello");console.log(obj1.list);//prints["hello"];当我将新的Child对象(继承包含名为list的数组变量的Pa

javascript - arguments.callee.toString() 和 arguments.callee.name 不返回函数名

我正在尝试获取当前正在运行的函数的名称。根据我的阅读,这应该可以使用:(arguments.callee.toString()).match(/function\s+(\[^\s\(]+)/)但是,当我在Firefox和Safari(Mac上的最新版本)中运行时,不会返回名称。console.log(arguments.callee)返回函数的源,但不返回分配的名称。arguments.callee.name返回空字符串。我的示例代码如下:vartestobj={testfunc:function(){console.log((arguments.callee.toString()).

javascript - jQuery/JavaScript : Defining a global variable within a function?

我有这个代码:varone;$("#ma1").click(function(){varone=1;})$("body").click(function(){$('#status').html("Thisis'one':"+one);})当我点击正文时,它说:这是“一个”:未定义。如何定义要在另一个函数中使用的全局变量? 最佳答案 从函数内部移除var。$("#ma1").click(function(){one=1;}) 关于javascript-jQuery/JavaScript:D

javascript - Phantomjs - 引用错误 : Can't find variable: $

我有一个PhantomJS脚本,当我在本地(Mac)运行它时它可以工作,但是当我在我的Linux服务器上运行它时,它返回以下错误:ReferenceError:Can'tfindvariable:$https://fantasy.premierleague.com/a/statistics/value_form:5712inglobalcode代码是:varpage=require('webpage').create();varfs=require('fs');varargs=require('system').args;page.settings.userAgent='Special

javascript - Jest : Mock ES6 Module with both default and named export

我有一个带有默认导出和命名导出的ES6模块:/**/src/dependency.js**/exportfunctionutilityFunction(){returnfalse;}exportdefaultfunctionmainFunction(){return'foo';}它被第二个ES6模块使用:/**/src/myModule.js**/importmainFunction,{utilityFunction}from'./dependency';//EDIT:Fixedsyntaxerrorincodesample//exportdefaultmyModule(){expor

javascript - 将 undefined variable 传递给函数时出错?

我正在尝试创建一个可重用函数来检查变量是否未定义。奇怪的是,当我将变量传递给函数以执行代码时它不起作用,但如果我在函数外部使用相同的逻辑,它就起作用了。有什么方法可以让这个函数isDefined起作用吗?//THISWORKSANDRETURNFALSEalert(typeofsdfsdfsdfsdf!=='undefined');//THISGIVESANERROR,WHY?//UncaughtReferenceError:sdfsdisnotdefinedfunctionisDefined(value){alert(typeofvalue!=='undefined'&&value!

javascript - 为什么下划线的 _.isUndefined(variable) 给出变量未定义的错误?

在Chrome中,我从这行代码console.log(_.isUndefined(targetNode));得到“UncaughtReferenceError:targetNodeisnotdefined”。我在执行console.log(targetNode===void(0));和console.log(targetNode);时遇到同样的错误。typeoftargetNode==="undefined"按预期返回true,但我的理解是void(0)比较更有效。我可以通过为targetNode设置默认值来解决这个问题,或者我可以只使用typeoftargetNode==="unde

javascript - 使用 data-template-name 命名 Ember.js 模板

我注意到Ember.js文档解释了命名模板的方法是通过设置标签的data-template-name模板名称的值。但在Ember.js文档站点上TomDale的最新截屏视频中,他使用ID命名模板。我假设它们都是在Ember中命名模板的有效方法。为什么要使用data-template-name与id相对应? 最佳答案 虽然两者都有效,但使用data-template-name可以让您自由使用不会与您的模板名称冲突的元素ID。 关于javascript-使用data-template-nam

javascript - 如何让 Chrome 调试器在处理 undefined variable 时中断或出错

我的Javascript代码(数百行)使Chrome挂起,当我调试该问题时,我发现一个变量未定义。我没有在控制台中收到错误。所以这使我的调试更加耗时,因为没有错误或异常或任何告诉我问题出在哪里的信息。我不想添加调试代码。有没有办法让调试器在运行时遇到undefinedvariable时发出错误、中断调试器或给出异常或显示任何对开发人员有用的信息?它不一定只适用于Chrome。 最佳答案 当出现JavaScript错误时,您可以使用PauseonJavaScriptExceptions进入DevTools调试器。特征。它有两种事件模式

go - 如何修复 'name' is undefined on object 错误?

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭3年前。Improvethisquestion我正在使用Go向bigpanda发出API发布请求。https://docs.bigpanda.io/reference#create-plan我有以下代码,当我尝试使APIpostgettingnameisundefinedonobjecterror时