作者:Truly
日期:2007.7.29

上次我们在《 <script type='text/javascript'>

function ABC()
{
    
this.member = 1;
    
this.method = Show;
}
function Show(a,b,c)
{
    
this.member = 123;
    
if(arguments.length==1)
        
if(arguments[0].constructor == Number)
            Show1_int.apply(
this, arguments);
        
else if(arguments[0].constructor == Date)
            Show1_date.apply(
this, arguments);
        
else
            Show1_string.apply(
this, arguments);
    
if(arguments.length==2)
        
if(arguments[0].constructor == Array)
            Show3.apply(
this,arguments);
        
else
            Show2.apply(
this,arguments);
}
function Show1_int(a)
{
    alert('
1 integer input parameter ' + a+ '  methode is called');
}
function Show1_string(a)
{
    alert('
1 string input parameter ' + a+ '  methode is called');
}
function Show1_date(a)
{
    alert('
1 date input parameter ' + a+ '  methode is called');
}

function Show2(a,b)
{
    alert('
2 input parameter is transfer:\na:'+a+'\nb:'++ '\nthe member is' + this.member);
}
// 演示引用方式传递
function Show3(a,b)
{
    arguments[
0][0]=2;
    alert('
2 input parameter is transfer:\na:'+a+'\nb:'++ '\nthe member is' + this.member);
}
var o = new ABC();
var arr = new Array();
arr[
0]=321;
o.method(arr[
0],2);    // 值传递
alert(arr[0]);        // 原始值未改变
o.method(arr,2);    // 引用方式传递
alert(arr[0]);        // 方法调用时被方法修改
o.method(new Date());

</script>

相关文章:

  • 2021-09-07
  • 2021-08-17
  • 2021-11-28
  • 2021-08-27
  • 2023-03-24
  • 2021-12-11
  • 2021-10-17
猜你喜欢
  • 2021-08-09
  • 2022-01-10
  • 2021-08-06
  • 2021-08-23
  • 2021-10-27
  • 2021-06-20
相关资源
相似解决方案