[Pkg-javascript-commits] [backbone] 46/74: added options argument to Backbone.Model initialize function
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:59:08 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.3.0
in repository backbone.
commit 771b87f17c2294483db565a7835f4ecfedf00823
Author: Raimonds Simanovskis <raimonds.simanovskis at gmail.com>
Date: Wed Nov 3 18:28:40 2010 +0200
added options argument to Backbone.Model initialize function
---
backbone.js | 4 ++--
test/model.js | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/backbone.js b/backbone.js
index 87560cd..7c0ccfd 100644
--- a/backbone.js
+++ b/backbone.js
@@ -107,12 +107,12 @@
// Create a new model, with defined attributes. A client id (`cid`)
// is automatically generated and assigned for you.
- Backbone.Model = function(attributes) {
+ Backbone.Model = function(attributes, options) {
this.attributes = {};
this.cid = _.uniqueId('c');
this.set(attributes || {}, {silent : true});
this._previousAttributes = _.clone(this.attributes);
- if (this.initialize) this.initialize(attributes);
+ if (this.initialize) this.initialize(attributes, options);
};
// Attach all inheritable methods to the Model prototype.
diff --git a/test/model.js b/test/model.js
index 04cfa90..312a6f3 100644
--- a/test/model.js
+++ b/test/model.js
@@ -38,6 +38,16 @@ $(document).ready(function() {
equals(model.one, 1);
});
+ test("Model: initialize with attributes and options", function() {
+ var Model = Backbone.Model.extend({
+ initialize: function(attributes, options) {
+ this.one = options.one;
+ }
+ });
+ var model = new Model({}, {one: 1});
+ equals(model.one, 1);
+ });
+
test("Model: url", function() {
equals(doc.url(), '/collection/1-the-tempest');
doc.collection = null;
--
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