I'm not able to understand what exactly is the difference by defining the function inside the class function & defining it as prototype. Here is my code.
PART 1
function myContent() {
this.toUserID = "1234";
this.loadMainLabel = function(url) {
alert("url:"+url);
}
}
var objMyContent = new myContent();
objMyContent.loadMainLabel("www.google.com");
PART 2
function myContent() {
this.toUserID = "1234";
}
var objMyContent = new myContent();
myContent.prototype.loadMainLabel = function(url) {
alert(url);
}
objMyContent.loadMainLabel("www.google.com");
Both gives the same output.. But, what exactly is the difference? Any thoughts would be appreciable.
Cheers!