OOPS in Javascriptpart 1
object?
object?instance of a type
instance of type dart frog
instances of type walrus
object?instance of a typetype represents anything a dart frog or a walrus
how to create objects?
how to create objects?let’s start with creating a type… say ‘dartfrog’
how to create objects?let’s start with creating a type… say ‘dartfrog’vardartfrog= function(){}
how to create objects?let’s start with creating a type… say ‘dartfrog’vardartfrog= function(){}type
adding properties andbehaviors
propertiesvardartfrog= function(){this.name = ‘’;this.color = ‘’;this.poisonous = true;}
propertiesvardartfrog= function(){this.name = ‘’;this.color = ‘’;this.poisonous = true;}properties
propertieslet’s fill the properties at the time of creation by passing values.vardartfrog= function(name, color, poisonous){this.name = name;this.color = color;this.poisonous = poisonous;}
behaviorsvardartfrog= function(name, color, poisonous){this.name = name;this.color = color;this.poisonous = poisonous;this.jump = function(){alert(“JUMP    JUMP     JUMP”);       } ;this.sing = function(){alert(“CROAK    CROAK   CROAK”);       }      }
behaviorsvardartfrog= function(name, color, poisonous){this.name = name;this.color = color;this.poisonous = poisonous;this.jump = function(){alert(“JUMP    JUMP     JUMP”);       } ;this.sing = function(){alert(“CROAK    CROAK   CROAK”);       }      }Methods or behaviors
let’s create some frogs and make them sing
creating objectsvarjackstraw = newdartfrog(“jackstraw”,                                                   “strawberry”,                                                   true);
creating objectsvarjackstraw = newdartfrog(“jackstraw”,                                                   “strawberry”,                                                   true);namecolorpoisonous?
creating objectsvarjackstraw = newdartfrog(“jackstraw”,                                                   “strawberry”,                                                   true);varstickyellow= newdartfrog(“stickyellow“,                                                    “yellow”,                                                     true);varblueman= newdartfrog(“blueman“,“blue”,                                                      true);
calling methodsGuys are you ready. come on sing!!jackstraw.sing();stickyellow.sing();blueman.sing();CROAK CROAKCROAKCROAK CROAKCROAKCROAK CROAKCROAK
ThankYou

OOPS in javascript