Reputation: 10261
...obscure to me, anyway. Can anyone tell me what this means? I have various bits of code that look like this:
node[foo](bar, function() {
...do something to 'node'
});
'node' is a single DOM node. 'foo' and 'bar' are both strings, though the code sets 'bar' to a boolean occasionally. The 'do something' code is occasionally executed, but only (I think) if 'bar' is true
. Thanks.
Upvotes: -1
Views: 343
Reputation: 116100
node
apparently has a property, of which the name is contained in foo
. The property contains (or refers to) a function. This function is called with the value of bar
and a callback function as its parameters.
Since objects can have extra properties assigned, a JavaScript library might set this 'foo' property of a node, even though it's not a native property of a DOM node. I believe JQuery uses this concept quite a lot.
Upvotes: 3