js:prototype
来源:互联网 发布:jsp写java代码 编辑:程序博客网 时间:2024/06/08 17:06
So we know that a class will have certain properties and methods, but what keeps track of what a given class can or can't do? What a class has or doesn't have? That is the job of the prototype.
JavaScript automatically defines the prototype for class with a constructor. For example, our Dog
constructor ensures that the Dog
prototype has abreed
property. Remember, the Dog
prototype keeps track of what Dog
has, doesn't have, can, or can't do.
Example:
function Dog (breed) {
this.breed = breed;
}
// here we make buddy and teach him how to bark
var buddy = new Dog("Golden Retriever");
buddy.bark = function() {
console.log("Woof");
};
buddy.bark();
// here we make snoopy
var snoopy = new Dog("Beagle");
// we need you to teach snoopy how to bark here
// this causes an error, because snoopy doesn't know how to bark!
snoopy.bark();
- prototype.js
- Prototype.Js
- prototype.js
- js prototype
- prototype.js
- prototype.js
- JS Prototype
- js prototype
- js prototype
- js prototype
- js prototype
- prototype.js
- Prototype.js
- js prototype
- js prototype
- js prototype
- js prototype
- Prototype.js
- EffectiveJava Item3:使用私有constructor 或者enum实现单例
- 1.7号 java.lang.ClassNotFoundException: Didn't find class "tv.pptv.MainActivity
- Collections.EMPTY_LIST和Collections.emptyList()简单使用心得
- 项目视频讲解_java邮件开发视频教程
- [推荐] VC与我的这四年[奇迹冬瓜] [问题点数:100分,结帖人runner2012] ——有感
- js:prototype
- 用OpenInventor实现的NeHe OpenGL教程-第六课
- 通过指定关键字在手册页中搜索信息
- 【Git笔记】运行man git时报错"No manual entry for git"的解决方法
- 数据结构④-链表
- 服务提供者框架(Service Provider Framework)
- iOS 富文本类库RTLabel
- 复习题目
- 【Android进阶学习】监听EditText的变化