1.

How can we make methods available on all objects?(a) Object.add(methods)(b) Object.methods(add)(c) Object.add.methods(…)(d) Object.prototypeI have been asked this question in final exam.The query is from Augmentation of Classes in chapter Classes and Modules in JavaScript of JavaScript

Answer» RIGHT choice is (d) Object.prototype

Easiest explanation: It is possible to ADD methods to Object.prototype, making them AVAILABLE on all objects. This is not recommended, however, because prior to ECMAScript5, there is no way to make these add-on methods non enumerable, and if you add properties to Object.prototype, those properties will be REPORTED by all for/in LOOPS.


Discussion

No Comment Found

Related InterviewSolutions