Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

private methods js

// Define class
class Car {
	// Initial parameters
    constructor(x, y) {
      this.x = x;
      this.y = y;
      this.acc = 0.2;
      this.speed = 0;
      this.crashed = false;
    }
  	// Public method
  	update() {
      this.#move();
      this.crashed = this.#detectCollisions();
    }
  	// Private method using '#'
  	#move() {
    	this.speed += this.acc;	
	}
    // Private method using '#'
    #detectCollisions() {
    	return getCollisions(this.x, this.y, traffic.x, traffic.y);
	}
}

// Calling Car class
var car = new Car(0, 0);
// Public method update calls private methods
car.update();
Comment

PREVIOUS NEXT
Code Example
Javascript :: redux actions.js 
Javascript :: order by type 
Javascript :: hostlistner 
Javascript :: assigning ID to view react native 
Javascript :: crontab validate regex 
Javascript :: javascript closest data attribute 
Javascript :: switch element array angular 
Javascript :: regular expression to validate m/d/yyyy HH:MM:SS AM 
Javascript :: how to setup material-table in react 
Javascript :: string to number javascript 
Javascript :: javascript download file 
Javascript :: javascript find method 
Javascript :: javascript set elements width by tag name 
Javascript :: mouse over jest 
Javascript :: remove property from object javascript 
Javascript :: schema mongoose 
Javascript :: javascript this Inside Constructor Function 
Javascript :: get time in google apps script 
Javascript :: svg event listeners 
Javascript :: react js calendar 
Javascript :: how to use hammerjs in ionic 5 
Javascript :: How to have hotjar in react-hotjar 
Javascript :: js ternaire 
Javascript :: react hooks in codepen 
Javascript :: javascript find area of triangle 
Javascript :: javascript create object from key value pairs 
Javascript :: send embed with webhook in JS 
Javascript :: vue 3 $refs 
Javascript :: creating room in ws node js 
Javascript :: transition scrolling 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =