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*/
//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*/
相关文章推荐
- JavaScript学习笔记整理_简单实现枚举类型,扑克牌应用
- JavaScript高级程序设计(第3版)学习笔记3 js简单数据类型
- JavaScript高级程序设计(第3版)学习笔记3 js简单数据类型
- javaScript如何简单而准确地判断复杂数据类型
- SilverLight学习笔记--Silverligh之在SL中调用Javascript (四种调用方法+简单与复杂参数的传递)
- SilverLight学习笔记--Silverligh之在Javascript中调用.NET(包括简单参数和复杂参数的操作)
- js的基本数据类型有哪些? ECMAScript中有5中简单数据类型(也称为基本数据类型): Undefined、Null、Boolean、Number和String。还有1中复杂的数据类型————
- 栋栋晓09:Javascript学习总结:基础知识1(语法、关键字和保留字、变量、数据类型、操作符)
- JavaScript基础学习<二>String类型
- JavaScrip学习之旅(11)JavaScript类型转换 (整型---浮点型)
- 黑马程序员-IOS学习笔记-C语言基础复杂数据类型
- JavaScript 简单入门学习笔记(四)
- 转:简单类型指针的与复杂类型指针定义以及分配的问题
- Entity Framework 学习中级篇1—EF支持复杂类型的实现
- JavaScript数据类型学习笔记
- javascript高级程序设计(第三版)-第三章 数据类型-学习笔记
- 学习javascript(二)-调试器与数据类型
- javascript基础学习(1)数据类型--number
- JavaScript学习笔记(二)——从简单开始学起
- Javascript学习笔记1 数据类型