Skip to content

Instantly share code, notes, and snippets.

@kimjoar
kimjoar / done.js
Created July 13, 2012 20:37
Done!
var Status = Backbone.Model.extend({
url: '/status'
});
var Statuses = Backbone.Collection.extend({
model: Status
});
var NewStatusView = Backbone.View.extend({
events: {
$(document).ready(function() {
$('#new-status').submit(function(e) {
e.preventDefault();
$.ajax({
url: '/status',
type: 'POST',
dataType: 'json',
data: { text: $(this).find('textarea').val() },
success: function(data) {
$('form').bind('submit', function() {
alert('User submitted form');
});
-var events = _.clone(Backbone.Events);
-
var Status = Backbone.Model.extend({
url: '/status'
});
-var Statuses = function() {
-};
-Statuses.prototype.add = function(text) {
- var status = new Status();
var events = _.clone(Backbone.Events);
Uncaught TypeError: Cannot call method 'add' of undefined
var events = _.clone(Backbone.Events);
@kimjoar
kimjoar / message.js
Created January 22, 2013 09:45
Nøstede modeller
var Message = Backbone.Model.extend({
parse: function(resp) {
resp.replies = new Messages(resp.replies);
return resp;
},
toJSON: function() {
var attributes = _.clone(this.attributes);
// evt: var attributes = Backbone.Model.prototype.toJSON.call(this)
// simpler render
render: function() {
var els = _.map(this._views, function(subview) {
return subview.render().el;
});
this.$el.empty().append(els);
}
@kimjoar
kimjoar / 1.md
Last active December 16, 2015 19:51
Transform Require.js modules to use simplified CommonJS wrapper

Transform your code from:

define(['backbone', './model', './mySync'], function(Backbone, Model, mySync) {

    var Collection = Backbone.Collection.extend({

        model: Model,
        sync: mySync