• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2. Function() > Executing a Function

Executing a Function

To execute a Function() object, you attach parentheses to the object, and any arguments you want passed to the function. To refer to the Function() object without executing the function, omit the parentheses and arguments. Listing 2.1 shows the difference between a function and its use as a constructor to create new objects.

Listing 2.1. The Difference Between a Function and Its Executed Results

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
function myFunc() {
   }
myObj = new myFunc()
alert(myObj.constructor) // returns myFunc function
myAlt = myFunc
alert(myAlt.constructor) // returns Function function
//-->
</script>
</body>
</html>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint