Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to invoke a function in a class

class Wizard{
  constructor(name, age, favoriteSpell){
    this.name = name;
    this.age = age;
    this.favoriteSpell = favoriteSpell;
  }
  // function that is being envoked
  castSpell() {
    console.log(`${this.name} has cast ${this.favoriteSpell}`)
  }
}

let gandolf = new Wizard('gandolf', 998, '')
gandolf.castSpell()
 
PREVIOUS NEXT
Tagged: #invoke #function #class
ADD COMMENT
Topic
Name
2+1 =