草庐IT

new_method

全部标签

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 - react .js : modify render() method for all components?

出于调试原因,我想将以下行添加到通用render()方法中,以便它在所有组件中执行。console.log('render'+this.constructor.displayName,this.state); 最佳答案 我假设您想在不更改任何现有代码的情况下执行此操作。我尝试了这个并找到了一种方法,如果您正在使用类似webpack或browserify的东西来构建您的应用程序并且您正在使用Reactv0.13。重要的是要注意,它使用私有(private)方法,进入React的内部,并且可能随时中断。也就是说,它可能对您的调试目的有用

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 - 使用@method 或@property 的JSDoc 对象方法?

JSDoc3的documentation包括这个例子:/***ThecompleteTriforce,oroneormorecomponentsoftheTriforce.*@typedef{Object}WishGranter~Triforce*@property{boolean}hasCourage-IndicateswhethertheCouragecomponentispresent.*@property{boolean}hasPower-IndicateswhetherthePowercomponentispresent.*@property{boolean}hasWisdo

javascript - 调用 Function.prototype.method() 时 TypeError : this. prototype is undefined

我正在读《Javascript:好的部分》这本书。现在我正在阅读有关增强类型的章节:Function.prototype.method=function(name,func){this.prototype[name]=func;returnthis;};更新:为什么下面的代码不起作用?js>Function.prototype.method("test",function(){print("TEST")});typein:2:TypeError:this.prototypeisundefined但是下面的代码没有问题:js>Function.method("test",function

javascript - 未捕获的类型错误 : Object [object Object] has no method 'apply'

我在创建的新网站上收到此UncaughtTypeError,但我无法找出导致该错误的原因。我在下面的链接中重现了这个问题,如果您查看浏览器的JS控制台,您会看到发生了错误,但没有其他任何反应。http://jsfiddle.net/EbR6D/2/代码:$('.newsitem').hover($(this).children('.text').animate({height:'34px'}),$(this).children('.text').animate({height:'0px'}));​ 最佳答案 确保将它们包装在异步回调

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

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

javascript - Selenium 网络驱动程序 : execute_script can't execute custom methods and external javascript files

我正在使用Selenium和Python,我正在尝试做两件事:导入外部javascript文件并执行其中定义的方法在字符串上定义方法并在求值后调用它们这是第一种情况的输出:测试.jsfunctionhello(){document.body.innerHTML="testing";}Python代码>>>fromseleniumimportwebdriver>>>f=webdriver.Firefox()>>>f.execute_script("vars=document.createElement('script');\...s.src='file://C:/test.js';\..

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

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

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.");