jjzjj

a_function_that_may_fail

全部标签

javascript - 为什么 function.apply() 不能在 IE 中跨文档边界工作?

我在IE中看到一些奇怪的行为,试图通过function.apply()调用另一个页面中的函数。这是一个简单的测试用例:test1.html:varopened=null;functionapplyNone(){opened.testFunc.apply(opened);}functionapplyArgs(){opened.testFunc.apply(opened,["appliedarray"]);}functioncall(){opened.testFunc("calleddirectly");}functionremoteApply(){opened.testApply(["u

javascript - 定义 `that = this` 将如何帮助我创建私有(private)变量/成员?

我正在阅读DouglasCrawford'spiece关于在javascript类中创建私有(private)变量。他在其中说您必须声明that=this以“使对象可用于私有(private)方法”。但是,我能够构建一个具有私有(private)成员、私有(private)方法和公共(public)方法的示例,而无需定义that=this:functionForm(id_code){//privatevariablevarid_code=id_code;varcolor='#ccc';//privatemethodfunctionbuild_style_attribute(){retu

javascript - 在 indexedDB 中检索数据时出现错误 "A mutation operation was attempted on a database that did not allow mutations."

我有这个简单的示例代码:varrequest=mozIndexedDB.open('MyTestDatabase');request.onsuccess=function(event){vardb=event.target.result;varrequest=db.setVersion('1.0');request.onsuccess=function(event){console.log("Successversion.");if(!db.objectStoreNames.contains('customers')){console.log("CreatingobjectStore"

javascript - Javascript 的 Function.toString() 的逆运算

对于Javascript应用程序,我需要能够让用户保存对象的状态。这涉及保存一组以前动态创建或通过GUI创建的自定义函数,并在以后加载这些存储的函数。本质上,我需要序列化和反序列化函数。现在我通过使用Function对象的.toString()方法实现序列化部分:func.toString().replace('"','\"').replace(/(\r)/g,'').replace(/(\n)/g,'').replace(/(\t)/g,'')这给了我这样美丽的“序列化”函数(注意该函数未命名):"function(someParameter){this.someFunctionNa

javascript - 语法错误 : invalid arrow-function arguments (parentheses around the arrow-function may help)

这样的代码会产生一个错误:if(hr>t1[0]||(hr==t1[0]&&min=>t1[1])&&hr错误:SyntaxError:无效的arrow-function参数(arrow-function周围的括号可能有帮助)这是什么意思,它是如何发生的?Google搜索此错误毫无用处。编辑:似乎是使用=>=而不是=引起的。但我仍然很好奇为什么错误是这样表述的,以及箭头函数应该是什么。编辑2.首先,我没有意识到这实际上可能是特定于浏览器的问题。另外,我没有意识到现在人们在浏览器上下文之外的其他地方使用JS。所以,为了说明这一点,我的浏览器是MozillaFirefox25.0.1。

javascript - 错误 : Zeptojs Animate Is Not A Function

zeptojs文档here当我使用$().animate函数时抛出如下错误:TypeError:$(...).animate不是函数而我使用的版本是页面提供的。 最佳答案 $(...).animate在zeptofx模块中。它不再在zepto的基本主要发行版中!http://zeptojs.com/#modules 关于javascript-错误:ZeptojsAnimateIsNotAFunction,我们在StackOverflow上找到一个类似的问题:

javascript - Angular : How can I transclude an element into a template that uses ng-repeat?

我有一个carousel指令,其中包括一些分块,用于将传入的items数组映射到元素结构数组的数组中,然后生成类似于以下伪代码的标记:这个Angular模板看起来像这样:[elementshouldbetranscludedintothisspot.]鉴于我的View代码:tagshouldappearinsidethe'carousel.html'template'sng-repeatlist.-->{{item.name}}我希望嵌入的元素绑定(bind)到最深的ng-repeat的item对象完整的Plunker和简化的测试用例可在此处获得:http://plnkr.co/edi

javascript - "bar"中 "var foo = function bar (){ ... }"的用途是什么?

在DouglasCrockford的书中,他将递归函数写为:varwalk_the_DOM=functionwalk(node,func){func(node);node=node.firstChild;while(node){walk(node,func);node=node.nextSibling;}}我从未见过定义为varfoo=functionbar(){...}的函数-我总是看到声明的右侧是匿名的:varfoo=function(){...}声明右侧的名称walk的唯一目的是缩短walk_the_DOM的调用吗?它们似乎成为相同功能的不同名称。也许我误解了这段代码的工作原理。

javascript - 基本 d3 : why can you select things that don't exist yet?

我一直在学习d3,我对选择有点困惑。考虑以下示例:http://bl.ocks.org/mbostock/1021841具体来说,让我们看一下这一行:varnode=svg.selectAll(".node").data(nodes).enter().append("circle").attr("class","node").attr("cx",function(d){returnd.x;}).attr("cy",function(d){returnd.y;}).attr("r",8).style("fill",function(d,i){returnfill(i&3);}).styl

javascript - arguments 属性可以通过 this.some_function.arguments 访问吗?其实我无法解释?

我在读一本JavaScript书,我在读如何通过原型(prototype)扩展JavaScript数组的数组功能,然后我来到这个我无法理解的例子,也没有对它进行深入的解释,我不是能够理解:Array.prototype.some_function=function(){varargs=this.some_function.arguments;//1varargs_length=this.some_function.arguments.length;//2...}//some_function在这里我能够访问参数,但我不知道这是如何工作的,意思是this指的是我们调用此方法的对象(在此上