我正在尝试重新设计一些我在SO上的答案中找到的Javascript代码.但我想首先更好地理解它的语法.其大纲是:
(function (root, ns, factory) {
// some code
} (window, 'detectZoom', function() {
// some more code
}));
Run Code Online (Sandbox Code Playgroud)
见接受的答案在这篇文章的参考完整的代码.
我理解最终结果如何实现,但我不太清楚内部(...)块如何与第一个相关,或者它内部的逗号分隔列表告诉编译器.
谁能解释一下?谢谢.
我需要到达此XML结构中的第一个节点进行一些更改:
<root-node>
<child mandatory="val">
...
</child>
<child mandatory="val" optional1="opt1">
...
</child>
<child mandatory="val" optional1="opt2" optional2="opt3">
...
</child>
</root-node>
Run Code Online (Sandbox Code Playgroud)
请注意,所有子项都具有强制属性,该属性在所有情况下都具有相同的值,以及一个或多个可选属性.但是,如果我做一个XPath,//root-node/child[@mandatory='val']我担心我也可能会引用其他节点,我不想触及.
有没有什么方法可以更具体,并排除其结构中存在某个属性的节点?
我遇到了Javascript计时器的问题.基本上,我有这两个页面元素:
<input type="checkbox" id="chk" />
<input type="button id="clearAll" value="Clear Timers" />
Run Code Online (Sandbox Code Playgroud)
以及管理它们的以下Javascript:
// store all page timers here
var timers = new Array();
// clears all page timers
function clearTimers () {
console.log("Clearing all timers.")
for (var i = 0; i< timers.length; i++)
clearTimeout (timers[i]);
}
// does stuff
function foo (whichTimer, interval) {
console.log("I am timer " + whichTimer + " running once every " + interval);
}
// document load
$(document).ready(function () {
$("#clearAll").click(clearTimers);
// check status at …Run Code Online (Sandbox Code Playgroud)