代码一:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
function Car (desc) {
this.desc = desc;
this.color = "red";
} // Car.prototype = {
// getInfo: function() {
// return 'A ' + this.color + ' ' + this.desc + '.';
// }
// };
//instantiate object using the constructor function
var car=new Car("bmw");
// var car = Object.create(Car.prototype);
// console.log(car.getInfo());
console.log(car instanceof Car);
console.log(car.color);
console.log(car.desc);
</script>
</head>
<body> </body>
</html>

以上code输出结果为:

true
red
bmw

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
function Car (desc) {
this.desc = desc;
this.color = "red";
} // Car.prototype = {
// getInfo: function() {
// return 'A ' + this.color + ' ' + this.desc + '.';
// }
// };
//instantiate object using the constructor function
// var car=new Car("bmw");
var car = Object.create(Car.prototype);
// console.log(car.getInfo());
console.log(car instanceof Car);
console.log(car.color);
console.log(car.desc);
</script>
</head>
<body> </body>
</html>

以上code输出结果:

true

undefined

undefined


问题来了:

通过new+构造函数构建实例,实例能访问构造函数的属性

通过Object.create(prototype)构建实例时,实例对象不能访问构造函数的属性

以上结果出现的理论依据在哪里。找出来

最新文章

  1. raspbian调整分辨率
  2. 【原创】相对完美的垂直居中popup(modal/dialog),无需监听window.resize事件
  3. UVA 1151
  4. Microsoft.Office.Interop.Word.Document.Open returns null on Windows Server 2008 R2
  5. Redis学习笔记(8)-发布/订阅
  6. HTML5与移动端Web
  7. 2016 - 1 -17 GCD主队列与全局队列
  8. 解决Genymotion下载设备失败的方法(Connection Timeout)
  9. connect to a specific wifi network in Android programmatically
  10. PHP解决网站高流量高并发问题
  11. HDU 5820 Lights(扫描线+zkw线段树)
  12. 文本框文字垂直居中 CSS
  13. Elasticsearch集成HanLP分词器-个人学习
  14. [20180806]tune2fs调整保留块百分比.txt
  15. Nuget EPPlus的使用
  16. java常量类编译问题
  17. HDU 1811 Rank of Tetris(并查集+拓扑排序 非常经典)
  18. IdentityServer4 密码模式实现
  19. PLSQL Developer windows 64位连接数据库的问题
  20. sql performance Kill Lock

热门文章

  1. android开源项目---View篇
  2. flex 光标(CursorManager)
  3. 实例讲解Nginx下的rewrite规则 来源:Linux社区
  4. 【CS Round #37 (Div. 2 only) D】Reconstruct Graph
  5. 在OEL 5.4 32bit上使用yum install命令遇到的问题
  6. 归并排序_分治算法 (白书P226)
  7. vue --- 全局守卫
  8. Lucene 定义
  9. Ubuntu 16.04下的LAMP环境配置
  10. zabbix3.4.7搭建及邮件告警