1. Home
  2. Docs
  3. Application Framework
  4. Javascript Framework
  5. Models

Models

mwp.model Model manager

Models are used to encapsulate your data and assign behaviors to it. A model is conceptually equivalent to a class, which you use to create new instances of objects that inherit your model methods.

Every model extends the core Backbone.Model class and therefore inherits all of the documented behaviors of a Backbone.js model in addition to some extra functionality provided by the MWP Javascript Framework.

@Reference

mwp.model( name, properties, classProperties ) Define a new class
mwp.model.get( name ) Get a model class
mwp.model.set( name, model ) Set (override) a model class explicitly

var AcmeWidget = mwp.model( 'acme-widget', {
    getFormalName: function() {
        return 'Mr. ' + this.get('name');
    }
});

var widget = new AcmeWidget({ name: 'Clean' });

console.log( widget.getFormalName() ); // Mr. Clean
Was this article helpful to you? Yes No

How can we help?