0

These two examples aren't making any difference. But I just want to know what is the use of object.prototype property. And tell me which is one is the standard procedure in Object Oriented Programming in Javascript. Any illustration would be nice.

var Person = function(){

  this.name = "John Doe"

}

Person.prototype.sayHello = function(){

  console.log( "Hi, I'm "+this.name );
}

var John = new Person();

John.sayHello();

and here is another example without object.prototype property

var Person = function(){

  this.name = "John Doe";

  this.sayHello = function(){

    console.log( "Hi, I'm "+this.name );

  }

}

var John = new Person();

John.sayHello();
DavidDomain
  • 14,976
  • 4
  • 42
  • 50

0 Answers0