Skip to content

Instantly share code, notes, and snippets.

@brettstimmerman
Created March 11, 2011 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettstimmerman/865291 to your computer and use it in GitHub Desktop.
Save brettstimmerman/865291 to your computer and use it in GitHub Desktop.
Duck punch Node.scrubVal's inability to handle empty arrays
<!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>
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