-1

...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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - it turns out that 'foo' was actually a jQuery function name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.