Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 692 Bytes

File metadata and controls

38 lines (26 loc) · 692 Bytes

Javascript : class

class Source Code

// example-class.js
class Movie {
  constructor(name, director) {
    this.name = name;
    this.director = director;
  }

  show() {
    console.log('show:' + movie.name);
    console.log('show:' + movie.director);
    console.log('show:' + this.#getName());
  }

  #getName() { // Private method
    return this.name;
  }

}

let movie = new Movie('Alien', 'Ridley Scott');

console.log('movie:name:' + movie.name);
console.log('movie:director:' + movie.director);

console.log('movie:Object.keys:' + Object.keys(movie))

movie.show();

// Error: private method '#getName' is not accessible
 // console.log(movie.#getName());