对象入门 object 代表所有的对象
对象:万物皆对象,对象就是一个具体的事物,一个具体的事物就会有行为和特性。
特征 | 功能 |
---|---|
属性 | 方法 |
对象实例:
- New
- Fuction
- Array
- RegExp
- Date
实例如下
<script>
// 定义一个对象
var teacher={};
//为对象添加属性
teacher.name='miss冯';
teacher.age='18';
teacher.hight='180';
//追加方法
teacher.attendClass=function(){
console.log('上课中。。。。。。');
}
console.log(teacher.age);
teacher.attendClass();//调用方法
// attendClass();
</script>
<script>
{ } 就是对象
//猫对象。
var cat = {};//对象
console.log(typeof, cat);//object
//对象添加属性:
cat.name = 'kitty';
cat.age = 2;
//追加方法
cat.catchMouse = function () {
console.log("抓到了jarry");
}
console.log(cat);
//键值对 key:value,key:value;
cat.name = '花花';//属性重新赋值,覆盖原来的属性;
consloe.log(cat);
//读取属性的值:
console.log(cat.name, cat.age);
</script>
编程更像一种艺术,不能只是作为技术活来看待。全面的思考、周密的准备、良好的构造不仅使程序更易于构建与调试,也使其更易理解和维护,而这正是系统成功的必要条件。作为真正的程序员,这并非可有可无的一种素质。所有的付出最终都会得到回报。