WebDev2 | OOP in JS: Week 7

Tutorials: Code Along , Const Function , Proto , Inherit
Blog Question: The new keyword is used with object oriented programming in JS by creating an empty object, sets the value of key word “this” to the empty object. It then adds return at end of function and later adds “proto” to empty the object.
function Fruit(apples, oranges, pears){
    this.apples = apples;
    this.oranges = oranges;
    this.pears = pears;
}
 var firstFruit = new Fruit(2,2,200);
 firstFruit.apples;
 firstFruit.oranges;
 firstFruit.pears;

Leave a comment

Your email address will not be published. Required fields are marked *

css.php