This function is fully used in JavaScript. VaR OBJ = { Yes: function (){ // This = OBJ This. Val = true; }, No: function (){ This. Val = false; } }; // We see that there is no Val property in the 'obj 'object Alert (obj. Val = NULL ); // We run the Yes function and it changes the Val Property // Associated with the 'obj 'object OBJ. Yes (); Alert (obj. Val = true ); // However, we now point window. No to the obj. No method and run it Window. No = obj. No; Window. No (); // This results in the OBJ object staying the same (as the context was // Switched to the window object) Alert (obj. Val = true ); // And window Val property getting updated. Alert (window. Val = false ); Some of the above processes are not quite the same. Javascript provides the call and apply methods to implement this function: // A simple that sets the color style of its context Function changecolor (color ){ This. style. Color = color; } // Calling it on the window object, which fails, since it doesn' t // Have a style object Changecolor ("white "); // Find the element with an ID of main VaR main = Document. getelementbyid ("Main "); // Set its color to black, using the call Method // The call method sets the context with the first argument // And passes all the other arguments as arguments to the Function Changecolor. Call (main, "black "); // A function that sets the color on the Body element Function setbodycolor (){ // The apply method sets the context to the body Element // With the first argument, the second argument is an array // Of arguments that gets passed to the Function Changecolor. Apply (document. Body, arguments ); } // Set the background color of the body to black setbodycolor ("black"); |