29. var Person = Backbone.Model.extend({ sayHello : function () { console.log(this.get('name')); } }); var me = new Person({name: 'Will'}); me.sayHello(); // -> 'Will'
30. var People = Backbone.Collection.extend({ sayHello : function () { this.map(function (person) { return this.get('name') + 'say: "Hello, I`m ' + this.get('name') + '."'; }); } }); var w3ctech = new People; w3ctech.add({name: 'Will'}, {name: 'Foo'}, {name: 'Bar'}); w3ctech.sayHello(); /** -> Will say: "Hello, I`m Will." * Foo say: "Hello, I`m Foo." * Bar say: "Hello, I`m Bar." **/
34. Mustache.js var obj = { peoples : [ { Name : 'Will' , Age : 15 , Sex : 'Man' }, { Name : 'Foo' , Age : 30 , Sex : 'Woman' }, { Name : 'Bar' , Age : 18 , Sex : 'Man' }], Man : function () { if ( this . Sex == 'Man' ) { return function ( text , render ) { render ( text ); } } } }; 对象