this.say = function() { return 'Hello! I am ' + this.name; }; }; var rodolfo = new Person('Rodolfo'); var rafael = new Person('Rafael'); console.log(rodolfo.say()); // 'Rodolfo' console.log(rafael.say()); // 'Rafael'
novo objeto usando o objeto literal // var this = {}; // adiciona propriedades e métodos ao this this.name = name; this.say = function() { return 'Hello! I am ' + this.name; }; // retorna this };
}; Person.prototype.say = function() { return 'Hello! I am ' + this.name; }; var rodolfo = new Person('Rodolfo'); var rafael = new Person('Rafael'); console.log(rodolfo.say()); // 'Rodolfo' console.log(rafael.say()); // 'Rafael'
</div> </div>V </script> <div id="box"></div> var source = $("#entry-template").html(); var template = Handlebars.compile(source); var context = { title: "My New Post", body: "My first post!" }; var html = template(context); $('#box').html(html);