prototype.js
具有以下功能
Event.observe(document, "dom:loaded", foo_function);
在执行foo_function
之前,它等待document
完成加载。如何将参数传递给foo_function
?类似的东西
Event.observe(document, "dom:loaded", foo_function, {arg1: bar_argument, arg2: baz_argument})
Event.observe(document, "dom:loaded", (function(e, bar_argument, baz_argument) {
//now bar_argument = bar,and baz_argument = baz
}).bindAsEventListener(this, bar, baz));
对于使用element.observe
并提取命名函数以获得更干净代码的人:
(function main() {
let myInteger = 0;
document.observe('dom:loaded', onDOMLoaded.bindAsEventListener(this, myInteger));
})()
function onDOMLoaded(event, integer) {
alert(integer);
}