Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

methods javascript

//Method is indicated by *
//Constructor Function
function BellBoy (name, age, hasWorkPermit, languages) {
  this.name = name;
  this.age = age;
  this.hasWorkPermit = hasWorkPermit;
  this.languages = languages;
  this.pickUpSuitcase = function() {//*object associated function (method) 
    console.log('suitcase is picked up')
  }
  this.move = function() {//*object associated function (method)
    console.log(`${this.name} is on the move`)
  }
  this.moveSuitcase = function() {//*object associated function (method)
    alert("May I take your suticase?");
      this.pickUpSuitcase(); this.move();
  } 
}

//Create New Object From Constructor Using Arguments
var bellBoy1 = new BellBoy('Earl E.Bird', 23, true, ['French', 'German'])

//Access the Properties and Their Values
console.log('Name : ', bellBoy1.name)
console.log('Age : ', bellBoy1.age)
console.log('Verified Work Permit : ', bellBoy1.hasWorkPermit)
console.log('Languages : ', bellBoy1.languages)

//calling the method
bellBoy1.moveSuitcase();
 
PREVIOUS NEXT
Tagged: #methods #javascript
ADD COMMENT
Topic
Name
2+8 =