您的位置:首页 > Web前端 > JavaScript

JavaScript学习--简单类型和复杂类型

2017-07-31 17:16 295 查看
/****************简单类型和复杂类型***************/
//JavaScript中简单数据类型有:number、string、boolean、undifined、null
   //复杂类型有:Object、Array、Date、function
   /*function Student(name,age,score){
    this.name=name;
    this.age=age;
    this.score=score;
   
    this.say=function(){
    alert("hello "+this.name);
    }
   }
   var s1=new Student("qiu",12,34);
   var s2=s1;
   alert(s2.name);
   s2.say();*/
  
   //基本类型作为函数的参数
   /*function f(a){
    a=100;
   }
   var x=1;
   f(x);
   alert(x);//输出1*/
   //总结:当基本类型作为函数的参数的时候,函数内部对参数的修改不会影响外部参数
   
   //数组作为函数的参数
   /*var arr=[1,2,3,4];
   function f(arr){
    arr[0]=-100;
   }
   alert(arr);//输出1,2,3,4*/
   
   //复杂类型作为函数的参数
   /*function Student(name,age,score){
    this.name=name;
    this.age=age;
    this.score=score;
   
    this.say=function(){
    alert("hello "+this.name);
    }
   }
   function f(stu){
    stu.name="xxx";
   }
   var s=new Student();
   f(s);
   alert(s.name);//输出xxx
   
   var stu=new Student("qiu",12,23);
   f(stu);
   alert(stu.name);//输出xxx
   
   function fn(stu){
    stu=new Student();
    stu.name="xxx";
   }
   var stu=new Student("qiu",12,23);
   fn(stu);
   alert(stu.name);//输出qiu
   
   function fnc(stu){
    stu=new Student("qiuzhiwen",12,34);
    stu.name="xxx";
   }
   var student=new Student("qiu",12,23);
   fnc(student);
   alert(student.name);//输出qiu*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐