jsでのオブジェクトの作成
1832 ワード
json方式、コンストラクション関数方式、Object方式、属性の削除とオブジェクトの破棄
<html>
<head>
<title>js </title>
<script type="text/javascript">
// json ,
var iphone5={
'pinpai':' ',
'price':'5300 ',
'color':' ',
'length':'15cm',
'msg':function(){alert(" ")},
'call':function(){alert(" ")}
};
alert(iphone5.color);// , iphone5
iphone5.msg();//
for(x in iphone5){
document.write(x+': '+iphone5[x]+'<br />');//
}
//
function ren(name){
this.name=name;//this
this.sex=" ";
this.weight=" ";
this.color=" ";
this.eat=function(){
alert(" ");
}
this.run=function(){
alert(" ");
}
}
var xiawa=new ren(" ");// ,
alert(xiawa.name);//
xiawa.sex=" ";// ,
xiawa.run();//
// Object :Object js
var obj=new Object();
obj.name=' ';
obj.height='180cm';
obj.run=function(){alert(" ")};//
obj.run();//
// ,
delete obj.name;//
obj=null;//
function paixu(arr){// ,
for(var i=0;i<arr.length;i++){
for(var j=i+1;j<arr.length;j++){
if(arr[i]>arr[j]){
var temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
return arr;
}
var arr=[23,324,321,11,23,34,32];
arr=paixu(arr);
document.write(arr);
</script>
</head>
<body>
</body>
</html>