Advertisement
apl-mhd

JavaScript Constructor

Oct 29th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     function Person(first, last, age, gender, interests) {
  3.         this.name = {
  4.             'first': first,
  5.             'last' : last
  6.         };
  7.         this.age = age;
  8.         this.gender = gender;
  9.         this.interests = interests;
  10.         this.bio = function() {
  11.             alert(this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. He likes ' + this.interests[0] + ' and ' + this.interests[1] + '.');
  12.         };
  13.         this.greeting = function() {
  14.             alert('Hi! I\'m ' + this.name.first + '.');
  15.         };
  16.     }
  17.  
  18.     var obj = new Person('apel', 'mahmud', 18,'male', 'Photography')
  19.  
  20.     console.log(obj.bio());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement