Function.apply()

JavaScript 1.3+, ECMAScript 1.0+, JScript 1.0+ Nav4.06+, IE 3+, Opera3+ Syntax

							function.apply()

Description

The apply() method of the Function object is used to apply a method of one object to another object. Using the apply() method keeps developers from rewriting methods for different objects.

Example

Listing 6.125 shows how the apply() method can be used between two objects. The bigHome function adds a new property, numRooms, to the home object.

Listing 6.125 Using the apply() Method
 <html> <body> <script lanuguage="JavaScript"> <!–– Hide // function defines a home with two properties function home(number, street){ var num = number; var str = street; document.write("house number is: " + num + "<br>"); document.write("Street ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.