Differences:
Byval is used to pass a value. The real parameter and the form parameter have different memory units, so they do not interfere with each other!
Byref transfer address. The real parameter and the form parameter occupy the same memory unit. If the form parameter is changed, the real parameter is changed !!!!!!
Easy to understand:
Byval is gone forever
Byref may be updated!
In javascript:
Boolean, number, and string parameters are passed by value ==> equivalent to byval in vbs;
Object parameters (including JS objects, array objects, and function objects) are passed by reference ==> equivalent to byref in vbs.
CopyCode The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml" lang = "ZH-CN">
<Head>
<Title> function value passing test </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Meta name = "author" content = "fengyan, cnlei"/>
<Meta name = "Copyright" content = "cnlei.y.l@gmail.com, http://www.cnlei.com"/>
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
<! --
Function num (n) {n = N * 2;} // number type parameter, passing by value => is equivalent to byval in vbs;
Function OBJ (){}
OBJ. Prototype. Show = function (o) {// JS object, which is passed by reference ==> equivalent to byref in vbs
O. tostring = function (){
Return ("{ID:" + this. ID + ", Desc:" + this. DESC + "}");
}
}
Function func (f) {// function object, which is passed by reference ==> equivalent to byref in vbs
F. Show = function (o ){
O. tostring = function (){
Return ("{ID:" + this. ID + ", Desc:" + this. DESC + ", tostring: function (){}}");
}
}
}
VaR N;
N = 1;
Alert (N );
Num (N );
Alert (N );
VaR O;
O = {
ID: "001 ",
Desc: "Number Description ",
Tostring: function (){
Return NULL;
}
};
VaR F = new OBJ ();
VaR F2 = new OBJ ();
Alert (O. ID + "\ n" + O. tostring ());
F. Show (O );
Alert (O. ID + "\ n" + O. tostring ());
Func (f );
F. Show (O );
Alert (O. ID + "\ n" + O. tostring ());
// -->
</SCRIPT>
</Body>
</Html>