InterviewSolution
| 1. |
Explain currying in JavaScript and implement multiply(2)(3)(4)(10) using it? |
|
Answer» In JavaScript EVERY object is created from a global “Object”(Notice the capital ‘O’). If we look at it in console, it have many properties and create been one of it. The Object.create() METHOD creates a new object, using an existing object as the prototype of the newly created object. Consider the below example, where we can create a new object from the existing object and can also add new properties to it or modify an existing property. Now, let see a practical use of Object.create in Inheritance. In below example we have an EMPLOYEE function, which have two functions in its Prototype. Then we have another function SalesEmployee and then set it’s Prototype to Employee’s Prototype. We also have a function in the prototype of SalesEmployee We then create an INSTANCE of the SalesEmployee as emp1 VARIABLE. It have all functions of Employee function and can also use it. |
|