现在的位置: 首页 > web前端 > 正文

JavaScript 对象有哪些

2020年05月20日 web前端 ⁄ 共 1385字 ⁄ 字号 评论关闭

  字符串、数值、数组、函数...此外,JavaScript允许自定义对象。funload=function(){//fun1()//注意,方法fun1实际上为window对象的一个属性,。下面学步园小编来讲解下JavaScript对象有哪些?

  JavaScript对象有哪些

  fun1=function(){

  varmessage="abcd";

  alert(message.length);

  alert(message.toUpperCase());

  }

  //定义并创建对象的实例

  fun2=function(){

  varperson=newObject();

  person.name="胖子小胖子";

  alert(person.name);

  //json方式声明对象

  varperson2={name:"火星人"};

  alert(person2.name);

  for(vartempinperson2){//对象属性可视为数组

  alert(person2[temp]);

  }

  }

  //使用函数来定义对象,然后创建新的对象实例

  fun3=function(){

  //this的使用

  vartemp=newfunction(){

  this.name="123456ACGDE";

  }

  alert(temp.name);

  }

  JavaScript对象有哪些

  //在JavaScript中,不会创建类,也不会通过类来创建对象(就像在其他面向对象的语言中那样)。JavaScript基于prototype,而不是基于类的。

  fun4=function(){

  functionfunTemp(name){

  this.name=name;

  };

  vartemp=newfunTemp("胖子胖子");

  temp.sex="男";//这里是设置对象temp的属性

  alert(temp.name+""+temp.sex);

  funTemp.prototype.age=20;//这里设置funTemp的prototype

  alert(temp.name+""+temp.sex+""+temp.age);

  vartemp2=newfunTemp("胖子小胖子");

  alert(temp2.name+""+temp2.sex+""+temp2.age);

  funTemp.enable=true;//这里设置funTemp的属性

  alert(temp2.enable+""+temp2.sex+""+temp2.age);

  vartemp3=newfunTemp("胖子大胖子");

  alert(temp3.enable+""+temp3.sex+""+temp3.age);

  //注意prototype

  //创建一个空白对象(newfunTemp("胖子胖子"))。

  //链接funTemp.prototype中的属性(键值对)到这个空对象中

  //将这个对象通过this关键字传递到构造函数中并执行构造函数。

  //将这个对象赋值给变量zhang。

  }

  以上就是关于“JavaScript对象有哪些”的内容,希望对大家有用。更多资讯请关注学步园。学步园,您学习IT技术的优质平台!

抱歉!评论已关闭.