<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" charset="utf-8">
//Object 所有类的基础类
//var obj = new Object();//不推荐
var obj = {}; //实例化对象 推荐方式
//给对象设置属性
obj.name = ‘李四‘;
obj.age = 20;
obj.sex = ‘男‘;
obj[‘birthday‘] = ‘1980‘; //用[]设置属性,注意[]内的引号
//obj.name=‘张三‘; 修改属性
//设置对象的方法
obj.say = function(){
alert(‘爱情到底是什么?‘);
}
//调用对象属性或方法
//alert(obj.name+obj.age);
// obj.say();
//delete 操作符,删除对象的属性或方法
/*
delete obj.age;
delete obj.sex;
delete obj.say;
alert(obj.name);
alert(obj.age);
alert(obj.sex);
obj.say();
*/
//for in 语句式 遍历一个js对象
/*
for(var attribute in obj){
alert(attribute +‘:‘+obj[attribute]);
}
*/
//constructor 保存对象的创建函数
//alert(obj.constructor);
//var arr = [1,2];
//alert(arr.constructor);
//hasOwnProperty(propertyName) :检测给定属性是否在当前对象中存在
//alert(obj.hasOwnProperty(‘sex‘));
//isPrototypeOf(Object) 检测原型
//检测给定属性、方法 是否能被 for in 枚举
//alert(obj.propertyIsEnumerable(‘say‘));
alert(obj.toLocaleString());
</script>
</head>
<body>
</body>
</html>
原文:http://www.cnblogs.com/lihaoyang/p/4947754.html