Possible Duplicate:
Use of ‘prototype’ vs. ‘this’ in JavaScript?
OK, So I am somewhat new to the idea of OOP in JS.
What is the difference between these two snippets of code written below:
function animal(){
this.name="rover";
this.set_name = function(name){
this.name = name;
}
}
function animal(){
this.name="rover";
}
animal.prototype.set_name = function(name){
this.name = name;
}
They both do the same thing, so what’s the difference?