Javascript-Classes - (5)



👉Classes


✅Classes are functions

To create a class in javascript, function has to be created. Though new javascript specifications introduced "class" keyword, it uses function internally.

We can also create properties and methods within class.

function customer ({
            this.CustomerCode = "1001";
            this.CustomerName = "John";
            this.getFullDetails = function(){
                  return this.CustomerCode + " " +                                         this.CustomerName";
            }
})

This is the basic syntax of class and it doesn't respect OOPs principles. Variables are attached to the windows object, hence the properties are global not private.

Comments

Popular posts from this blog

Javascript-OOPs(Part2)-AbstractionAndEncapsulation- (8)

Javascript-OOPs(Part4)-Polymorphism- (10)

Javascript-OOPs(Part1)-Objects - (7)