JavaScript prototype of object
来源:互联网 发布:平湖校区网络教学平台 编辑:程序博客网 时间:2024/05/18 00:43
Every JavaScript object has a second JavaScript object (or null , but this is rare) associated with it. This second object is known as a prototype, and the first object inherits properties from the prototype.so, if we want to know about prototype, firstly we should know about object.object, it is the foudamental datatype of JvaScript.any value in JavaScript that is not a string, a number, true , false , null , or undefined is an object.
now, let us turn to the basic prototype of Object. the following example is easy appliction of prototype.
function baseClass()
{
this.showMsg = function()
{
alert("baseClass::showMsg");
}
}
function extendClass()
{
}
extendClass.prototype = new baseClass();
var instance = new extendClass();
instance.showMsg(); // 显示baseClass::showMsg
In this exampel,the result shows function extendClass() using the property of baseClass .
function baseClass()
{
this.showMsg = function()
{
alert("baseClass::showMsg");
}
}
function extendClass()
{
this.showMsg =function ()
{
alert("extendClass::showMsg");
}
}
extendClass.prototype = new baseClass();
var instance = new extendClass();
instance.showMsg();//显示extendClass::showMsg
however,this program runs is not like the last example.so ,we can see ,the propotype in some degree,just as the variable.when local variable is not exist,it can find the closey related variable.so if we want to use the instance of extendClass to call the function of baseClass. How can we do?
Do not worry .there is the solution below(use call funtion).
extendClass.prototype = new baseClass();
var instance = new extendClass();
var baseinstance = new baseClass();
baseinstance.showMsg.call(instance);//显示baseClass::showMsg
- JavaScript prototype of object
- javascript prototype object
- javascript中Object.prototype.toString
- Object & Array of JavaScript
- JavaScript中Object 对象的Prototype属性
- JavaScript中prototype、__proto__、Function、Object等
- [翻译]JavaScript秘密花园 - Object, Prototype
- JavaScript:Object.prototype.toString方法的原理
- JavaScript:Object.prototype.toString方法的原理
- JavaScript:Object.prototype.toString方法的原理
- JavaScript Object.prototype.constructor属性详解
- Javascript——Object.prototype.hasOwnProperty()
- JavaScript:Object.prototype.toString方法的原理
- JavaScript:Object.prototype.toString方法的原理
- JavaScript之浅谈object.prototype.toString.call()
- JavaScript:Object.constructor == Object.prototype.constructor 返回 false
- Object.prototype
- OReilly JavaScript The Good Parts 关于Object.prototype和delete
- run文件的安装
- bzoj1070: [SCOI2007]修车-费用流
- PHP中常量的定义
- Gradle打jar包,包含所有依赖
- 经典算法题一览
- JavaScript prototype of object
- 【项目 4:穷举法解决组合问题】
- (4.5.3.2)android studio编译项目,9 patch图片报错Crunching Cruncher
- 二叉树系列——二叉树的最大距离(即相距最远的两个叶子节点,编程之美,百度面试题)
- shell之dns_zone的配置含义
- python execfile()和locals()函数
- Hdu 1051(贪心思想)
- KUKA安装选项包
- 5GHz WiFi是骗人的吗?