草庐IT

new_variable

全部标签

javascript - JS : How can I prevent access to the global variables do?

就是在我想要的函数中禁用全局变量。我想做AdobeAfterEffects的扩展示例代码:functionprivateFunction(){returnwindow;}然后通常:result:WindowObject但我想要:result:undefined我该怎么办?请帮帮我我想阻止函数中的全局变量访问; 最佳答案 用局部变量隐藏全局变量:functionprivateFunction(){varwindow;returnwindow;//nottheWindow,butundefinednow}

javascript - new String() 的行为不像对象那样的数组

varnice=newString("ASH");nice;//String{0:"A",1:"S",2:"H",length:3,[[PrimitiveValue]]:"ASH"}varreverseNice=Array.prototype.reverse.call(nice);reverseNice.toString();//"ASH"而我期望reverseNice是“HSA”。 最佳答案 不能改nice,试试看;nice[0]='f';nice[0];//"A"如果您想使用Array方法,请先将其转换为真正的Arrayvarr

javascript - new Date() 在 Chrome 或 Firefox 中显示不同的结果

奇怪的是,新的Date()会在不同的浏览器中产生不同的结果。在Chrome45.0.2454.101m中:newDate(2015,9,1)ThuOct01201500:00:00GMT+0200(W.EuropeDaylightTime)在Firefox40.0.3中(默认检查器/控制台)newDate(2015,9,1)Date2015-09-30T22:00:00.000Z附加信息如果我在Firefox中尝试使用FIREBUG扩展的控制台,它会像Chrome一样运行良好。发生了什么?似乎Firefox没有计算偏移量,实际上它比正确日期晚了2小时。我在其他工作站上做了测试,似乎都有

javascript - 量子对偶性 : variable is null and undefined at the same time?

考虑以下JavaScript代码(在Firefox中测试):functionf(a){if(a==undefined){alert('undefined');}if(a==null){alert('null');}}f();同时显示两个警报,表明这两个陈述都是正确的。你能给出一个合理的解释吗? 最佳答案 ==是一个“软”相等运算符。它使用类型强制将两个等效对象比较为相等。以下所有都是正确的:42=="42"0==false0==""[]==""{}=="[objectObject]"'/(?:)/'==newRegExp相反,您应该

javascript - 使用 `new Function` 和性能问题

我正在通过AJAX加载一个脚本文件,并运行它的内容,我正在这样做:newFunction('someargument',xhr.responseText)(somevalue);但是,根据MDN:FunctionobjectscreatedwiththeFunctionconstructorareparsedwhenthefunctioniscreated.Thisislessefficientthandeclaringafunctionandcallingitwithinyourcode,becausefunctionsdeclaredwiththefunctionstatement

javascript - "new new Something"如何在 JavaScript 中产生有效结果?

我目前正在开发一个JavaScript解析器并研究ECMAScript5.1specification.这是一个让我困惑的问题。§11.2Left-Hand-SideExpressions定义了以下NewExpression产生式:NewExpression:MemberExpressionnewNewExpression如果我没看错的话,NewExpression可能是这样的newnewSomething(实际上,任何数量的新。)这让我很困惑。newSomething怎么可能返回任何你可以再次new的东西?有可能吗? 最佳答案 它

javascript - 如何检查三元运算符中的 undefined variable ?

我对三元运算有疑问:leta=undefined?"Defined!":"DefinitelyUndefined",b=abc?"Defined!":"DefinitelyUndefined",//ReferenceErrorc=(abc!==undefined)?"Defined!":"DefinitelyUndefined",//ReferenceErrord=(typeofabc!=="undefined")?"Defined!":"DefinitelyUndefined"//results:a=d="DefinitelyUndefined",//whilebandcthrowR

javascript - 保护构造函数以防止丢失 'new' 是一种好习惯吗?

FromSecretsoftheJavascriptNinja(很棒的演练顺便说一句)://WeneedtomakesurethatthenewoperatorisalwaysusedfunctionUser(first,last){if(!(thisinstanceofUser))returnnewUser(first,last);this.name=first+""+last;}varname="Resig";varuser=User("John",name);assert(user,"Thiswasdefinedcorrectly,evenifitwasbymistake.");

javascript - new MyFunction() 与 new(MyFunction)

我正在查看Vowsdocumentation并且在几个地方它使用语法varmyVar=new(MyFunction);例如varpromise=new(events.EventEmitter);我熟悉newMyFunction()和newMyFunction(是的,我已经阅读了thisquestion)。但是上面的语法对我来说是新的——它看起来像一个函数调用,但我怀疑它只是添加了一些括号的newMyFunction。这些使用new的方式有什么区别吗?如果不是,是否有任何好的论据支持使用其中之一?我原以为newMyFunction()是最清晰的。如果这是重复的,我深表歉意-我搜索过但找不

javascript - typescript : Unexpected token; 'constructor, function, accessor or variable'

我用类型脚本编写了以下类。当我编译它时,它会出错说"src\main\MqttClientWrapper.ts(24,2):错误TS1068:意外的token。一个构造或者,需要方法、访问器或属性。”。下面是我的代码。varmqtt:any=require('mqtt');exportinterfaceIWillMessage{topic:string;payload:string;qos:number;retain:string;}exportinterfaceIMessageReceivedCallBack{onMessageReceived(message:string);}ex