Hello,
To check argument types in functions that are used in many different
places, I have been using this:
Hello,
To check argument types in functions that are used in many different
places, I have been using this:
function someCoreFunction( domnode, text ) {
// "Cheap runtime assert": fails when `domnode` is not a DOM node.
domnode.childNodes.a;
// Same idea, for a string.
text.substring.a;
// Rest of the function
// ...
}
It helps to catch mistakes early, including during development. I am
*not* advocating to litter the code with thousands such statements,
but in a few strategical places the benefits can exceed the costs.
Hopefully this can help someone. Constructive feedback is welcome.
Guillaume
function someCoreFunction( domnode, text ) {
// "Cheap runtime assert": fails when `domnode` is not a DOM node.
domnode.childNodes.a;
// Same idea, for a string.
text.substring.a;
// Rest of the function
// ...
}
It helps to catch mistakes early, including during development. I am
*not* advocating to litter the code with thousands such statements,
but in a few strategical places the benefits can exceed the costs.
Hopefully this can help someone. Constructive feedback is welcome.
Guillaume
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en