Blogger Information
Blog 22
fans 0
comment 0
visits 21699
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js基础知识(9月11日作业)
岑勋的博客
Original
715 people have browsed it

编程: 创建对象的方式(字面量或构造函数)

1、通过对象直接量创建的对象,都具有同一个原型对象,并可以通过Object.prototype获得对原型对象的引用,即创建的对象继承自Object.prototype

实例

<script>
let obj = {'color':'cyan','size':36,'type':'sport'};
document.write(obj);
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

2、通过关键字new和构造函数调用创建的对象的原型就是构造函数(Object()、Array()、Date()、RegExg())的prototype属性的值

实例

<script>
let point = new Object({x:10,y:20});
document.write(point);
let person = new Object();
person.name = 'yaoming';
person.height = 216;
person.sports = function(){
    return 'play basketball';
}
document.write(person);
document.write(person.sports());
document.write(person.name);
document.write(person['height']);
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post