Folling are the code sample for the static menthod on class.
1:- A static method is implemented on a class
Remark Point:-
A static method cannot be called like below
1:- A static method is implemented on a class
class Multiplication{ static multiply(number) { if (number === undefined) { number = 1; } return number * number; } }2:- A class with a static member can be sub-classed.
class HugeMultiplication extends Multiplication { static multiply(number) { return super.multiply(number) * super.multiply(number); } }3:- A Static method can be called like below
console.log(Multiplication.multiply()); ///1 console.log(Multiplication.multiply(6)); // 36 console.log(HugeMultiplication.multiply(5));625
Remark Point:-
A static method cannot be called like below
var multi = new Multiplication(); console.log(multi.multiply()); // Uncaught TypeError: multi.multiply is not a function
No comments:
Post a comment