Backbone js getter
Make shape with get bacbonejs
by erick
HTML
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>
<h1><b>Learn How to use Backbone JS</b></h1>
<hr>
<hr>
<hr>
<div class='shape'/>
JavaScript
var Shape = Backbone.Model.extend({
defaults: { x:50, y:50, width:150, height:150, color:'black' },
setTopLeft: function(x,y) {
this.set({ x:x, y:y });
},
setDim: function(w,h) {
this.set({ width:w, height:h });
}
});
var shape = new Shape();
shape.bind('change', function() {
$('.shape').css({ left: shape.get('x'),
top: shape.get('y'),
width: shape.get('width'),
height: shape.get('height'),
background: shape.get('color') });
});
shape.set({ width: 100 });
shape.setTopLeft(100, 300);