[Pkg-javascript-commits] [backbone] 124/281: unifying property-or-function logic.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:03 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.0
in repository backbone.
commit c3852b8cd1c7f77c24dbf4e0da43793c7706591a
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Mon Dec 19 10:54:50 2011 -0500
unifying property-or-function logic.
---
backbone.js | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/backbone.js b/backbone.js
index 8438e72..1e8f506 100644
--- a/backbone.js
+++ b/backbone.js
@@ -128,8 +128,7 @@
var defaults;
attributes || (attributes = {});
if (options && options.parse) attributes = this.parse(attributes);
- if (defaults = this.defaults) {
- if (_.isFunction(defaults)) defaults = defaults.call(this);
+ if (defaults = getValue(this, 'defaults')) {
attributes = _.extend({}, defaults, attributes);
}
this.attributes = {};
@@ -293,7 +292,7 @@
// using Backbone's restful methods, override this to change the endpoint
// that will be called.
url : function() {
- var base = getUrl(this.collection) || this.urlRoot || urlError();
+ var base = getValue(this.collection, 'url') || this.urlRoot || urlError();
if (this.isNew()) return base;
return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + encodeURIComponent(this.id);
},
@@ -938,8 +937,7 @@
// This only works for delegate-able events: not `focus`, `blur`, and
// not `change`, `submit`, and `reset` in Internet Explorer.
delegateEvents : function(events) {
- if (!(events || (events = this.events))) return;
- if (_.isFunction(events)) events = events.call(this);
+ if (!(events || (events = getValue(this, 'events')))) return;
this.undelegateEvents();
for (var key in events) {
var method = this[events[key]];
@@ -1035,7 +1033,7 @@
// Ensure that we have a URL.
if (!options.url) {
- params.url = getUrl(model) || urlError();
+ params.url = getValue(model, 'url') || urlError();
}
// Ensure that we have the appropriate request data.
@@ -1116,11 +1114,11 @@
return child;
};
- // Helper function to get a URL from a Model or Collection as a property
+ // Helper function to get a value from a Backbone object as a property
// or as a function.
- var getUrl = function(object) {
- if (!(object && object.url)) return null;
- return _.isFunction(object.url) ? object.url() : object.url;
+ var getValue = function(object, prop) {
+ if (!(object && object[prop])) return null;
+ return _.isFunction(object[prop]) ? object[prop]() : object[prop];
};
// Throw an error when a URL is needed, and none is supplied.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list