1 <!DOCTYPE HTML>2 <HTML>3 <HeadLang= "en">4 <MetaCharSet= "UTF-8">5 <title></title>6 7 <Scripttype= "Text/javascript">8 //The first way of defining9 functionfn1 () {Ten Alert ("fn1"); FN1 One } A //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 (typeoffn1 ()); function - the //since the function is an object, all can be defined by the following way - //at this point fn2 points to the same function as FN1, but JS is different from Java: - //1. In Java, key is placed on the stack, the function is placed in memory, that is, the fn1 is placed on the stack, the function value is placed in memory - //at this point fn2 = fn1, an object fn2 is recreated in the stack, although the function that fn2 points to is still the same as the function that fn1 points to. + //But the function of fn2 and FN1 is no longer part of the memory, unlike Java, which is still a memory area . - varfn2=fn1; + fn2 (); FN1 A fn1= function(){ at Alert ("fnn1"); - } - //Although a function is an object, it differs from an object in that it is a reference to the assignment of the completion object, - //and the function is actually done through the copy of the object. - //so fn1 changed, but it doesn't affect fn2. - fn2 (); FN1 in fn1 (); Fnn1 - to /** + * For an object, the assignment is done by referring to the pointer, at which point the modified O1 or O2 will have two modifications only, in the same way as in Java - * @type {Object} the */ * varO1= NewObject (); $ varO2=O1;Panax Notoginseng O2.name= "LEON"; - alert (o1.name); LEON the + A </Script> the + </Head> - <Body> $ $ </Body> - </HTML>
The difference between JS object and function