Guest User

Untitled

a guest
Aug 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. /*
  2. Polymorphism means "many forms" and in programming describes the ability
  3. for objects to present the same interface for different behaviors. So calling
  4. man.sayHello() and woman.sayHello() would result in different output, even
  5. though the method call is the same.
  6. */
  7.  
  8. function Person(gender) {
  9. this.gender = gender;
  10. this.sayHello = function () {
  11. console.log("Hello, I am a " + this.gender);
  12. }
  13. }
  14.  
  15. var man = new Person("man");
  16. var woman = new Person("woman");
  17. man.sayHello(); // --> "Hello, I am a man"
  18. woman.sayHello(); // --> "Hello, I am a woman"
Add Comment
Please, Sign In to add comment