JavaScript Learning Note 05

Source: Internet
Author: User

Functions of JavaScript

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en"
"Http://www.w3.org/TR/html4/strict.dtd" >

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>js01_hello</title>
<meta name= "Author" content= "Administrator"/>
<script type= "Text/javascript" >
The first way of defining
function fn1 () {
Alert ("Fn1");
}
A function is a very special object, an instance of a function class, in which operations stored in memory are stored by a key-value pair.
Alert (typeof fn1);

Because a function is an object, you can define it by the following way
The following is a copy of the function to complete the assignment, two references do not point to the same object
var fn2 = fn1;
FN2 ();
FN1 = function () {
Alert ("Fnn1");
}
/**
* Although a function is an object, it differs from the object in that it is assigned by reference to the completion object, and the function is done by copying the object.
* So fn1, although changed, does not affect FN2
*/
FN2 ();
FN1 ();

/**
* For objects, the assignment is done by referring to the pointer, and modifying O1 or O2 will modify the two values
*/
var O1 = new Object ();
var O2 = O1;
O2.name = "Leon";
alert (o1.name);
</script>
<body>
</body>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en"
"Http://www.w3.org/TR/html4/strict.dtd" >

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>js01_hello</title>
<meta name= "Author" content= "Administrator"/>
<script type= "Text/javascript" >
function sum (num1,num2) {
return num1+num2;
// }
var sum = function (num1,num2) {
return num1+num2;
}

function sum (NUM1) {
return num1+100;
// }
/**
* The space pointed to by sum has been changed from a function with two parameters to a function with only NUM1
* Only NUM1 functions are called at the time of invocation
* Special Note: function parameters and calls are not related, if the function has only one parameter, but it is passed in
* Two parameters, just match one
* So there is no overloaded function in JS
*/
var sum = function (NUM1) {
return num1+100;
}

Functions are defined in the following way
/**
* defined in the following way equals a defined
* function fn (num1,num2) {
* Alert (NUM1+NUM2);
* }
* So through the following example, a full description of the function is an object
*/
var fn = new Function ("Num1", "num2", "Alert (' Fun: ' + (NUM1+NUM2))");
FN (12,22);
Alert (sum (19));

Alert (sum (19,20));
</script>
<body>
</body>

JavaScript Learning Note 05

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.