mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #3507 from akre54/matches-with-callback
Matches with predicate
This commit is contained in:
@@ -421,7 +421,7 @@
|
||||
|
||||
// Special-cased proxy to underscore's `_.matches` method.
|
||||
matches: function(attrs) {
|
||||
return _.matches(attrs)(this.attributes);
|
||||
return !!_.iteratee(attrs, this)(this.attributes);
|
||||
},
|
||||
|
||||
// Set a hash of model attributes on the object, firing `"change"`. This is
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"version" : "1.1.2",
|
||||
"main" : "backbone.js",
|
||||
"dependencies" : {
|
||||
"underscore" : ">=1.6.0"
|
||||
"underscore" : ">=1.7.0"
|
||||
},
|
||||
"ignore" : ["docs", "examples", "test", "*.yml", "*.html", "*.ico", "*.md", "CNAME"]
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"keywords" : ["model", "view", "controller", "router", "server", "client", "browser"],
|
||||
"author" : "Jeremy Ashkenas <jeremy@documentcloud.org>",
|
||||
"dependencies" : {
|
||||
"underscore" : ">=1.6.0"
|
||||
"underscore" : ">=1.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coffee-script": "1.7.1",
|
||||
|
||||
@@ -216,6 +216,19 @@
|
||||
strictEqual(model.matches({'name': 'Jonas', 'cool': false}), false);
|
||||
});
|
||||
|
||||
test("matches with predicate", function() {
|
||||
var model = new Backbone.Model({a: 0});
|
||||
|
||||
strictEqual(model.matches(function(attr) {
|
||||
return attr.a > 1 && attr.b != null;
|
||||
}), false);
|
||||
|
||||
model.set({a: 3, b: true});
|
||||
|
||||
strictEqual(model.matches(function(attr) {
|
||||
return attr.a > 1 && attr.b != null;
|
||||
}), true);
|
||||
})
|
||||
|
||||
test("set and unset", 8, function() {
|
||||
var a = new Backbone.Model({id: 'id', foo: 1, bar: 2, baz: 3});
|
||||
|
||||
920
test/vendor/underscore.js
vendored
920
test/vendor/underscore.js
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user