javascript学习

2015/4/2

1.Object.create

https://msdn.microsoft.com/zh-cn/library/ff925952

Animal = Object.create(Object);
Animal.getName = function() {
  return this.name;
};

Dog = Object.create(Animal);
Dog.speak = function() {
  return "woof";
};

var dog = Object.create(Dog);
dog.name = "Scamp";
console.log(dog.getName() + ' says ' + dog.speak());

 我的理解:相当于是new的作用。但是比通过构造函数的方式创建对象来的慢(效率低)。

posted @ 2015-04-02 18:53  PaganMonkey  阅读(90)  评论(0编辑  收藏  举报

喜欢的话可以打赏一下哦!!!

支付宝

微信