class HealthCheck.js sum / Abstraction / #of function (private)

 


class HealthCheck {

constructor(s, d, h, hr) {

this.systolic = s;
this.diastolic = d;
this.hemoglobin = h;
this.heartRate = hr;

}

#BPTest() {

console.log(`BP value is : ${this.systolic} / ${this.diastolic}`);

if (this.systolic > 160 || this.diastolic > 90)
console.log("High BP");

else if (this.systolic < 90 || this.diastolic < 60)
console.log("Low BP");

else
console.log("Normal BP");

}

Heartcheck() {

this.#BPTest(); // this is invoking the function BP test as we need the data here too

console.log((this.heartRate > 100 || this.heartRate < 80) ? "Unsafe" : "Safe");

}

SugarTest() {

this.#BPTest(); // this is invoking the function BP test as we need the data here too

console.log(this.hemoglobin > 10 ? "Sugar Patient" : "No Sugar");

}

}

let person1 = new HealthCheck(92, 55, 12, 88); // invoking the class HealthCheck for person1
instance

let person2 = new HealthCheck(164, 88, 9, 88); // invoking the class HealthCheck for person2
instance

person1.Heartcheck() // now the object or instance person1 of class HealthCheck is
// invoking the method HeartCheck(), so only the data of person1
// related to HeartCheck will get printed in the console.

//////////////////////////////////////////////////////////////////////////////////////////////
TERMINAL:










Implementation of BPTest is hidden from outside scope and the
process of hiding the implementation details from outside
environment is called "Abstraction".

The function which is having a # in front of it can be called
only within that class , it cannot be called outside the class.
And the #of function can only be declared inside a class.



I

Comments

Popular posts from this blog

car.js

movie.js