Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including backbone-model with all npm packages installed. Try it out:

var backboneModel = require("backbone-model")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

backbone-model v1.0.10

Backbone Models extracted to a separate module

backbone-model

Backbone models as a discrete component, with sync stripped out.

This has been run against the official Backbone test suite and passes all tests.

Installation

Install with npm(1):

$ npm install --save backbone-model

Install with component(1):

$ component install green-mesa/backbone-model

API

Normal usage


  var Model = require('backbone-model').Model;

  var MyModel = Model.extend({ someShizzle : "Hello world"});

  var myInstanceOfMyModel = new MyModel();

Adding Backbone Sync functionality.

You need to $ component install green-mesa/backbone-sync (which, by the way, will also install jQuery. Fun times. A non-jQuery replacement would be good at this point)


    var Model = require('backbone-model').Model;
    var sync = require('backbone-sync').sync;
    
    Model.prototype.sync = function(){

        return sync.apply(this, arguments);

    };

Some commonJS related quirks mean that overridding the ajax handler is a bit pointless as you've already got jQuery installed by default. Write a replacement backbone-sync module and use that instead. That's the component way.

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free