Function

JavaScript functions are objects. They can be defined using the Function constructor, like so:

    var sum = new Function('a', 'b', 'return a + b;'); 

This is a (generally not recommended) alternative to the function literal (also known as function expression):

    var sum = function (a, b) { 
      return a + b; 
    }; 

Or, the more common function definition:

    function sum(a, b) { 
      return a + b; 
    } 

The Function.prototype members

Following are the list of members of the Function constructor:

Property/Method

Description

apply(this_obj, params_array)

Allows you to call another function while overwriting the other function's this value. The first parameter that apply() accepts is the object to be bound to this inside the function and the second is an array ...

Get Object-Oriented JavaScript - Third Edition 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.