Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

adding methods to objects 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();
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript fetch api 
Javascript :: sequelize get data 
Javascript :: array==null array.length java script 
Javascript :: streami node js 
Javascript :: check if a string matches a regex javascript 
Javascript :: are you sure you want to close this window javascript 
Javascript :: how i do button when click open a new tab in react 
Javascript :: extends vs includes use case 
Javascript :: create a customer in stripe node.js 
Javascript :: npm md to html 
Javascript :: isupper 
Javascript :: javascript isempty 
Javascript :: find multiples of a number 
Javascript :: fix slow loading images in react 
Javascript :: convert json data to a html table 
Javascript :: first node prog using express 
Javascript :: gojs update text 
Javascript :: it each jest 
Javascript :: javascript traversing 
Javascript :: absolute price in javascript 
Javascript :: how to get form all filed with properties in jquery 
Javascript :: angularjs How to get Capacitor Storage values before doing http call IONIC 6 
Javascript :: mariadb javascript 
Javascript :: Conditional expressions and in fandom explained examples 
Javascript :: summer note empty 
Javascript :: check if an element is displayed jquery 
Javascript :: how to connect socket in react js 
Javascript :: angular http post example 
Javascript :: express send image bufffer 
Javascript :: js backwards loop 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =