You can add prototype to any object in Jacascript likes Object, Array, String...

prototype 有继承的作用,比如说我有一个String的对象,我可以访问Object的prototype hasPrototype() function,

StrObj -- String --Object,

你每创建的一个StrObj, 它之所以可以使用.shift(), pop(), push() methods是应为那些methods都是String object继承下去的。

Array.prototype.countCattle = function ( kind ){
var numKind = 0;
for(var i = 0; i<this.length; i++){
if(this[i].type == kind){
numKind++;
}
}
return numKind;
};
alert(canyonCows.countCattle("calf")+valleyCows.countCattle("bull")+forestCows.countCattle("cow"));
Object.prototype.noCalvesYet = function () {
if(this.type == "cow" && this.hadCalf == null){
return true;
}
return false;
};
Array.prototype.countForBreeding = function(){
var numToBreed = 0;
for(var i = 0; i < this.length; i++){
if(this[i].noCalvesYet()){
numToBreed++;
}
}
return numToBreed;
};

[Javascript] Prototype 1的更多相关文章

  1. [原创]javascript prototype 对象 函数 <精简的美丽......>

    精简的美丽...... javascript prototype 对象 函数 在javascript中我们都知道创建一个对象使用如下代码var x = {}对象可以拥有属性和方法var x = {   ...

  2. javascript prototype原型链的原理

    javascript prototype原型链的原理 说到prototype,就不得不先说下new的过程. 我们先看看这样一段代码: <script type="text/javasc ...

  3. JavaScript Prototype in Plain Language

    非常好的文章: http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/ jan. 25 2013 14 ...

  4. JavaScript prototype原型用法

    JavaScript对象原型 所有JavaScript对象都从原型继承属性和方法. <!DOCTYPE html> <html> <meta charset=" ...

  5. illustrating javascript prototype & prototype chain

    illustrating javascript prototype & prototype chain 图解 js 原型和原型链 proto & prototype func; // ...

  6. HTML 学习笔记 JavaScript (prototype)

    原博地址:http://www.cnblogs.com/dolphinX/p/3286177.html 原博客的作者是一个非常牛逼的前端大神,我作为一个初学者,在此借助大神的博客进行自己的学习.在这里 ...

  7. 关于 JavaScript prototype __proto__ 一点总结

    http://www.cnblogs.com/wbin91/p/5265163.html 先上代码 function(y) Foo{ this.y = y;} Foo.prototype.x = 10 ...

  8. JavaScript prototype 使用介绍

    用过JavaScript的同学们肯定都对prototype如雷贯耳,但是这究竟是个什么东西却让初学者莫衷一是,只知道函数都会有一个prototype属性,可以为其添加函数供实例访问,其它的就不清楚了, ...

  9. JavaScript——Prototype详探

    用过JavaScript的同学们肯定都对prototype如雷贯耳,但是这究竟是个什么东西却让初学者莫衷一是,只知道函数都会有一个prototype属性,可以为其添加函数供实例访问,其它的就不清楚了, ...

  10. JavaScript prototype应用

    //JavaScript自定义功能 //1,去除字符串两端空格 String.prototype.trim = function() { var start, end; start = 0; end  ...

随机推荐

  1. sql分组排序取top

    写法1: use anypay; select tr.* from (select task_code, max(created_at) as cal from task_log group by t ...

  2. Cipolla算法学习小记

    转自:http://blog.csdn.net/doyouseeman/article/details/52033204 简介 Cipolla算法是解决二次剩余强有力的工具,一个脑洞大开的算法. 认真 ...

  3. mac下递归创建ctags报错: "illegal option -- R"

    在mac系统下不论是使用vim还是sublime text2的ctags插件都会碰到“illegal option -- R”这个错误,原因是mac使用的是自己的ctags,而我们通常在linux或w ...

  4. PHP--SPL扩展学习笔记

    一. SPL是干嘛的 SPL是用于解决典型问题(standard problems)的一组接口与类的集合. 数据结构: .实现双向列表 SplDoublyLinkedList implements I ...

  5. poj 1330 Nearest Common Ancestors 单次LCA/DFS

    Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19919   Accept ...

  6. HDU step by step

    section 1 不解释~ section 2 1.2.1 a+b coming #include<stdio.h> long long z,x,y; int main( ) { whi ...

  7. centos7 docker安装和使用_入门教程

    说明:本文也是参考互联网上的文章写的,感谢相关作者的贡献. 操作系统 64位CentOS Linux release 7.2.1511 (Core) 配置好IP:192.168.1.160 修改yum ...

  8. macbook pro 开发帮助

    java安装目录 /Library/java/JavaVirtualMachines/ 设置快捷目录 vim .bash_profile 文件中追加一下信息:export dirname=目录路径 重 ...

  9. HDU 4706 Children's Day (水题)

    Children's Day Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  10. Android - Mount a Samba share

    Mount Manager, Cifs manager :Manage your CIFS/NFS network shares was working, but the command from t ...