Skip to content

Commit

Permalink
Extend extends. Useful for plugins patterns: var opts = $.extend({}, …
Browse files Browse the repository at this point in the history
…default, argOptions)
  • Loading branch information
John Boxall committed Jun 7, 2011
1 parent a8103c7 commit 2b55a40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/zepto.js
Expand Up @@ -64,7 +64,12 @@ var Zepto = (function() {
}
}

$.extend = function(target, source){ for (key in source) target[key] = source[key]; return target }
$.extend = function(target){
slice.call(arguments, 1).forEach(function(source) {
for (key in source) target[key] = source[key];
})
return target;
}
$.qsa = $$ = function(element, selector){ return slice.call(element.querySelectorAll(selector)) }

function filtered(nodes, selector){
Expand Down
4 changes: 4 additions & 0 deletions test/zepto.html
Expand Up @@ -241,6 +241,10 @@ <h1>Zepto DOM unit tests</h1>
var obj = {};
t.assertIdentical(obj, $.extend(obj, {a: 1}));
t.assertEqual(1, obj.a);

obj = {};
t.assertIdentical(obj, $.extend(obj, {a: 1}, {b: 2}))
t.assertEqual(2, obj.b);
},

testDollar: function(t){
Expand Down

0 comments on commit 2b55a40

Please sign in to comment.