How can you add a method to an object in JavaScript?

  • a) By using the Object.addMethod() method.
  • b) By defining a function and assigning it as a property of the object.
  • c) By using the Object.method() function.
  • d) By using the object.method = function() syntax.
You can add a method to an object in JavaScript by defining a function and assigning it as a property of the object. For example, myObject.myMethod = function() { /* method code */ };. While you can use various patterns and techniques for method definition, there's no standard Object.addMethod() or Object.method() function.
Add your answer
Loading...

Leave a comment

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