attachevent

Scope troubles in Javascript when passing an anonymous function to a named function with a local variable

大憨熊 提交于 2019-12-01 18:38:00
Sorry about the title - I couldn't figure out a way to phrase it. Here's the scenario: I have a function that builds a element: buildSelect(id,cbFunc,...) Inside buildSelect it does this: select.attachEvent('onchange',cbFunc); I also have an array that goes: var xs = ['x1','x2','x3'...]; Given all of these, I have some code that does this: for(var i = 0; i < xs.length; i++) { buildSelect(blah,function(){ CallBack(xs[i],...) },...); } The issue is that when onchange gets fired on one of those selects it correctly goes to CallBack() but the first parameter is incorrect. For example if I change

What happens if I call a JS method with more parameters than it is defined to accept?

大城市里の小女人 提交于 2019-11-28 00:50:24
I'd like to know both for regular all-in-the-family JS developer(me)-defined functions, as well as predefined DOM methods. Like what happens if I try to call IE's attachEvent with the signature of the WHATWG's addEventListener ? For instance, elem.attachEvent('onbillgates\'mom', function(e){ this.mount(); }, false); Specifically, note the false . Will that trip anything up, even though the attachEvent method's signature only calls for two arguments? Thanks. function foo(FirstOf2, SecondOf2) { console.log(FirstOf2 + SecondOf2); } foo(1, 2, true); JavaScript doesn't have the concept of a fixed

What happens if I call a JS method with more parameters than it is defined to accept?

為{幸葍}努か 提交于 2019-11-26 14:45:15
问题 I'd like to know both for regular all-in-the-family JS developer(me)-defined functions, as well as predefined DOM methods. Like what happens if I try to call IE's attachEvent with the signature of the WHATWG's addEventListener ? For instance, elem.attachEvent('onbillgates\'mom', function(e){ this.mount(); }, false); Specifically, note the false . Will that trip anything up, even though the attachEvent method's signature only calls for two arguments? Thanks. function foo(FirstOf2, SecondOf2) {

Correct usage of addEventListener() / attachEvent()?

▼魔方 西西 提交于 2019-11-26 06:54:49
I'm wondering how to use addEventListener respectively attachEvent correctly? window.onload = function (myFunc1) { /* do something */ } function myFunc2() { /* do something */ } if (window.addEventListener) { window.addEventListener('load', myFunc2, false); } else if (window.attachEvent) { window.attachEvent('onload', myFunc2); } // ... or function myFunc1() { /* do something */ } if (window.addEventListener) { window.addEventListener('load', myFunc1, false); } else if (window.attachEvent) { window.attachEvent('onload', myFunc1); } function myFunc2() { /* do something */ } if (window

Correct usage of addEventListener() / attachEvent()?

别来无恙 提交于 2019-11-26 01:58:04
问题 I\'m wondering how to use addEventListener respectively attachEvent correctly? window.onload = function (myFunc1) { /* do something */ } function myFunc2() { /* do something */ } if (window.addEventListener) { window.addEventListener(\'load\', myFunc2, false); } else if (window.attachEvent) { window.attachEvent(\'onload\', myFunc2); } // ... or function myFunc1() { /* do something */ } if (window.addEventListener) { window.addEventListener(\'load\', myFunc1, false); } else if (window