Function Object Instance Properties
This section provides a tutorial example on how to use an instance properties of a function to share values across multiple function calls.
As an object, a function can also have its own instance properties. An instance property of a function can also be viewed as a static variable whose value persists across multiple function calls.
The tutorial example below shows you how to use an instance property of a function to share values across multiple function calls.
// Function_Own_Properties.js // Copyright (c) 2013 by Dr. Herong Yang, herongyang.com var sign = new Function("name", "this.signature = name;" + "sign.count++;" ) sign.count = 0; // Executing it on the current object sign("Herong"); // Applying it on another object var java = new Object(); sign.apply(java, new Array("Sun")); // Calling it on another object var pc = new Object(); sign.call(pc, "IBM"); // # of times the function has been called println("Call counts: " + sign.count);
Call counts: 3
Table of Contents