javascript簡略
5090 ワード
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
/*
function Person(){} // , ,
var p1 = new Person();
alert(typeof p1);
*/
/*
var per = new Object();
per.name = ' ';
alert(per.name);
*/
/*
//
var = new ();
function Person(){} //
var p1 = new Person(); //
// .
p1.name = 'zhangsan';
p1.age = 23;
p1.marry = false;
alert(p1.name+':'+p1.age+':'+p1.marry);
alert(typeof p1);
*/
/*
//
alert(p.constructor); constructor
alert(typeof p); typeof
alert(p instanceof person) instanceof
*/
/*
this
1. js , , this “ ”
2. js ,this window
*/
/*
//
function Person(){}
var p1 = new Person();
p1.name='xiao';
p1.age = 30;
for(var i in p1){
document.write(p1[i]+'<hr>');
}
for(var i in window){
document.write(i+'<br>');
}
*/
/*
//
delete .
*/
/*
function Person() {}
var p1 = new Person();
p1.name = 'lis';
p1.age = 33;
p1.speak = function(){
alert(" "+this.name);
}
p1.speak();
*/
//json
/*
var json = {
name : 'lisi',
age :23,
addr : ' '
};
alert(json.name); // .
*/
/*
var json = [{
name : 'lis',
age : 23,
email : '[email protected]'
},{
name : 'wang',
age : '25',
email : '[email protected]'
}
];
alert(json[1].name);
*/
//
/*
//1. , , 。
//
function Person(){}
var p1 = new Person();
p1.age = 23;
Person.prototype.address = 'beijing'; // address
Pseron.prototype.speak = function(){ // speak
alert(this.name);
}
//2.
function Person(){}
var p1 = new Person();
p1.name = 'zhangsan';
p1.age = 23;
alert(p1.hasOwnProperty('name'));
*/
</script>
</body>
</html>