Created
March 29, 2014 06:31
-
-
Save vinitkumar/9849609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proy.on("all", function (eventName) { | |
object.trigger(eventName); | |
}); | |
book.on({ | |
"change:title": titleView.update, | |
"change:author": authorPane.update, | |
"destroy": bookView.remove | |
}); | |
// off object.off([event], ['callback', ['context']) | |
// | |
// remove just the 'onChange' callback | |
// | |
object.off("change", onChange); | |
// remove all change callbacks | |
object.off("change"); | |
// Remove the `onchange` callbacks for all events | |
object.off(null, null, context); | |
// remoe all callbacks on '`object`' | |
object.off(); | |
// listenTo | |
// | |
// tell an object to listen to a particular event. | |
view.listenTo(model, 'change', view.render); | |
view.stopListening(); | |
view.stopListening(model); | |
view.listenToOnce(model, 'change', view.render); | |
add, remove, reset, sort, change, change:[attribute] | |
destroy, request, sync, error, invalid, route:[name] | |
route, all | |
// Models | |
var Sidebar = Backbone.Model | |
// Models | |
var Sidebar = Backbone.Model.extend({ | |
promtColor: function () { | |
var cssColor = promt("Please enter a css color"); | |
this.set({color: cssColor}); | |
} | |
}); | |
window.sidebar = new Sidebar; | |
sidebar.on('change:color', function(model, color) { | |
$('#sidebar').css({ background: color }); | |
}); | |
sidebar.set({ color: 'white' }); | |
sidebar.promtColor(); | |
// # extend | |
// To create a model class of your own, you extend Backbone.Model and | |
// provide instance properties | |
// extend properly sets up the prototype chain, so subclasses created | |
// with extend can be further extended and subclassed as you like. | |
var Note = Backbone.Model.extend({ | |
initialize: function () {}, | |
author: function () {}, | |
allowedToEdit: function (account) { | |
return true; | |
} | |
}); | |
var PrivateNote = Note.extend({ | |
allowedToEdit: function(account) { | |
return account.owns(this); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment