How can a method be added to an object's prototype?

  • object.prototype.addMethod(methodName, method)
  • prototype.addMethod(object, methodName, method)
  • Object.prototype.methodName = method
  • object.methodName = method
To add a method to an object's prototype in JavaScript, you can assign the method to the prototype property of the constructor function that created the objects. For example, Object.prototype.methodName = method. This way, all objects created from that constructor will inherit the method. The other options do not follow the correct syntax for adding a method to a prototype.
Add your answer
Loading...

Leave a comment

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