Function Object Inherited Properties and Methods

This section provides a tutorial example on how to Function object inherited properties and methods.

Because a function is an object of the Function type, it has some interesting inherited properties and methods:

The tutorial example below shows you how to use the properties and methods inherited in a Function object:

// Function_Properties_and_Methods.js
// Copyright (c) 2013 by Dr. Herong Yang,

   var sign = new Function("name",
      "this.signature = name;"

   println("Function body: " + sign.toString());

   println("# of parameters: " + sign.length);

// Executing it on the current object
   println("this.signature: " + this.signature);

// Applying it on another object
   var java = new Object();
   sign.apply(java, new Array("Sun"));
   println("java.signature: " + java.signature);

// Calling it on another object
   var pc = new Object();, "IBM");
   println("pc.signature: " + pc.signature);

Run this JavaScript file with "jrunscript" in a command window, you will get:

Function body:
function anonymous(name) {
    this.signature = name;

# of parameters: 1
this.signature: Herong
java.signature: Sun
pc.signature: IBM

Very cool. Everything worked as I expected. One small surprise is that the name of a function object created with the Function constructor is "anonymous".

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

Using Functions as "Function" Objects

 Functions Are Objects of the "Function" Type

 Using the Function Constructor

Function Object Inherited Properties and Methods

 Function Object Instance Properties

 Creating Function Objects with "function" Statements

 Creating Function Objects with the "function" Operator

 Comparing 3 Ways of Creating Functions

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications


 PDF Printing Version