Javascript学习笔记2
Javascript学习笔记2 before we get started, let’s review the way we Create a Class: 开始之前,我们先复习一下Class的建立方式: function Person(name,age) { this.name = name; this.age = age; } // Let's make bob again, using our constructor var bob = new Person("Bob Smith", 30);* 1 * 2 * 3 * 4 * 5 * 6 * 7 1.注入method into Class Prototype to Rescue – 实际是注入method into Class,要注意对比独立于Class之外的function也能实现类似的。不过原理不同。 比如: function Dog (breed) { this.breed = breed; }; var bark = function(){ //这种就是独立于class之外的,与后面object就无关了。 console.log("Woof"); }; // here we make buddy and teach him how to bark var buddy = new Dog("golden Retriever"); //Dog.
…