Using Backbone models with AngularJS

后端 未结 7 1560
攒了一身酷
攒了一身酷 2021-01-30 02:11

Recently I was thinking about the differences and similarities between Backbone.js and AngularJS.

What I find really convenient in Backbone are the Backbone-Models and t

7条回答
  •  终归单人心
    2021-01-30 03:06

    Had a similar idea in mind and came up with this idea: Add just a getter and setter for ever model attribute.

    Backbone.ngModel = Backbone.Model.extend({
            initialize: function (opt) {
             _.each(opt, function (value, key) {
                 Object.defineProperty(this, key, {
                     get: function () {
                         return this.get(key)
                      },
                     set: function (value) {
                         this.set(key, value);
                     },
                     enumerable: true,
                     configurable: true
                 });
             }, this);
         }
     });
    

    See the fiddle: http://jsfiddle.net/HszLj/

提交回复
热议问题