Home / CSE / Javascript - CS :: Discussion

Discussion :: Javascript - CS

  1. How can we make methods available on all objects?

  2. A.

     Object.add(methods)

    B.

     Object.methods(add)

    C.

     Object.add.methods(…)

    D.

     Object.prototype

    View Answer

    Workspace

    Answer : Option D

    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 nonenumerable, and if you add properties to Object.prototype, those properties will be reported by all for/in loops.


Be The First To Comment