Created
March 11, 2011 01:07
-
-
Save brettstimmerman/865291 to your computer and use it in GitHub Desktop.
Duck punch Node.scrubVal's inability to handle empty arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Duck punch Node.scrubVal's inability to handle empty arrays</title> | |
</head> | |
<body> | |
<ul> | |
<li>One</li> | |
<li>Two</li> | |
<li>Three</li> | |
</ul> | |
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script> | |
<script src="node-scrubval-fix.js"></script> | |
<script> | |
function test(Y) { | |
var nodes = Y.all('li'); | |
// These should always return NodeLists | |
console.log( | |
nodes.slice(0), | |
nodes.splice(2), | |
nodes.concat(nodes); | |
); | |
// These should normally return empty arrays, | |
// and return empty NodeLists with the fix applied | |
console.log( | |
nodes.slice(5), | |
nodes.splice(3), | |
Y.all('.none').concat(Y.all('.none')) | |
); | |
} | |
YUI().use('node', test); | |
YUI().use('node', 'node-scrubval-fix', test); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI.add('node-scrubval-fix', function (Y) { | |
var scrubVal = Y.Node.scrubVal; | |
Y.Node.scrubVal = function () { | |
var val = scrubVal.apply(null, arguments); | |
return Y.Lang.isArray(val) ? Y.all(val) : val; | |
}; | |
}, '0.0.1', { requires: ['node-base'] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment