js关于 byval 与 byref 的区别
作者:CNLei 来源:CNLei.blog 发布时间:2007-10-13 10:48:00
js关于 byval 与 byref 二者区别:
byval 传递数值,实参和形参分处不同的内存单元,互不干扰!
byref 传递地址,实参和形参占用相同的内存单元,形参变则实参变!!!!!!
通俗理解:
byval 一去不复返
byref 进去再出来,可能被更新!
在JavaScript中:
Boolean,Number,String型的参数是按值传递的 ==> 相当于VBS中的ByVal;
而Object型的参数(包括JS对象,Array对象,Function对象等),是按引用传递 ==> 相当于VBS中的ByRef
<!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> 函数传值测试 </title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="枫岩,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型的参数,按值传递的 ==> 相当于VBS中的ByVal;
function Obj(){}
Obj.prototype.show = function(o){ //JS对象,是按引用传递 ==> 相当于VBS中的ByRef
o.toString = function(){
return("{id:"+this.id+",desc:"+this.desc+"}");
}
}
function Func(f){ //Function对象,是按引用传递 ==> 相当于VBS中的ByRef
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:"编号说明",
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>
在JavaScript中:
Boolean,Number,String型的参数是按值传递的 ==> 相当于VBS中的ByVal;
而Object型的参数(包括JS对象,Array对象,Function对象等),是按引用传递 ==> 相当于VBS中的ByRef
<!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> 函数传值测试 </title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="枫岩,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型的参数,按值传递的 ==> 相当于VBS中的ByVal;
function Obj(){}
Obj.prototype.show = function(o){ //JS对象,是按引用传递 ==> 相当于VBS中的ByRef
o.toString = function(){
return("{id:"+this.id+",desc:"+this.desc+"}");
}
}
function Func(f){ //Function对象,是按引用传递 ==> 相当于VBS中的ByRef
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:"编号说明",
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>
猜你喜欢
- 区块链比特币从诞生到现在已经10年了,最近接触到了区块链相关的技术,为了揭开其背后的神秘面纱,我就从头开始构建一个简单的区块链。从技术上来看
- 1、应该将 CSS 放置于结构的上方(一般放置于 head 元素内)。CSS 是解释型语言,Firefox 和 IE 在等待 CSS 传输完
- vue-router切换组件时使组件不销毁默认地,使用vue-router切换组件时,离开的组件会被销毁,新进入地组件会创建。那么,有时候,
- 指定结果集的列名AS 子句可用来更改结果集列名或为导出列指定名称。当结果集列由对表或视图中的列的引用进行定义时,结果集列的名称与所引用列的名
- Flask数据模型和连接数据库flask是基于MTV的结构,其中M指的就是模型,即数据模型,在项目中对应的是数据库。flask与数据库建立联
- 简述在大多数此类教程中都会不遗余力的介绍如何使用数据库。今天我们对数据库暂且不表,而是来关注另一个在web应用中很重要的特性:如
- 每位SQL Server开发员都有自己的首选操作方法。我的方法叫做分子查询。这些是由原子查询组合起来的查询,通过它们我可以处理一个表格。将原
- 表中主键必须为标识列,[ID] int IDENTITY (1,1)1.分页方案一:(利用Not In和SELECT TOP分页)语句形式:
- TCP是建立可靠连接,并且通信双方都可以以流的形式发送数据。相对TCP,UDP则是面向无连接的协议。使用UDP协议时,不需要建立连接,只需要
- 常有新手问我该怎么备份数据库,下面介绍3种备份数据库的方法:(1)备份数据库文件MySQL中的每一个数据库和数据表分别对应文件系统中的目录和
- 在处理数据的时候,因为没有及时的去重,所以需要重新对生成txt进行去重。可是一个文件夹下有很多txt,总不可能一个一个去操作,这样效率太低了
- 没事在这里发一下关于数据库大批量插入数据的效率对比,用ACCESS和MSSQL,数值是在本机测试,根据不同的环境和配置,数值可能会有较大差别
- 1.点算子点算子是两个像素灰度值间的映射关系,属于像素的逐点运算,相邻像素不参与运算。点算子是最简单的图像处理手段,如:亮度调整、对比度调整
- 如何用JMail同时给多人发信?在ASP中,为什么我在Jmail收件人处指定多个收件人时,像这样:JMail.AddRecipient&nb
- 1. 介绍1.1 前言NetworkX是复杂网络研究领域中的常用Python包。1.2 图的类型(Graph Types)允许以可哈希的ob
- 本文实例讲述了Django实现简单分页功能的方法。分享给大家供大家参考,具体如下:使用django的第三方模块django-pure-pag
- 字符串是Python中最常用的数据类型1、创建字符串1.1 使用 ’ ’ 或 " &quo
- # -*- coding: utf-8 -*-# @Time : 2019-11-18 09:31# @Author : cxa# @Fil
- 代码生成器介绍client-go为每种k8s内置资源提供了对应的clientset和informer。那么我们要监听和操作自定义资源对象,应
- 工资excel表格格式如下所示:使用python批量给每位员工发送工资条信息,格式如下:思路:首先是加载excel,获取当前sheet表格s