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. ubuntu16.04服务器apache的ssl证书配置

    背景:在腾讯云申请的免费证书1年,服务器ubuntu 16.04版本,我的是多域名 1.ssl模块的安装 sudo a2enmod ssl //开启apache ssl模块 a2ensite defa ...

  2. JAVA规范

    ---------------------------------------------------------- Web Service技术 --------------------------- ...

  3. LOJ P3952 时间复杂度 noip 暴力 模拟

    https://www.luogu.org/problemnew/show/P3952 模拟,日常认识到自己zz. #include<iostream> #include<cstdi ...

  4. bzoj 3668 数位DP

    收获: 1.如果有很多位操作,并且不包含+-×/等高级运算,那么可以一位一位考虑,如果求一个最优解,可以尝试逐位确定,这道题因为原始攻击值有范围,那么就需要数位DP. /*************** ...

  5. python开发_html_html处理

    ''' python中,html模块提供了只提供了一个方法: html.escape(s, quote = True) 该方法主要是把html文件中的特殊字符(&,<,>,&quo ...

  6. Codeforces Round #352 (Div. 2) B. Different is Good 水题

    B. Different is Good 题目连接: http://www.codeforces.com/contest/672/problem/B Description A wise man to ...

  7. Bootstrap_表格

    Bootstrap 表格 Bootstrap 提供了一个清晰的创建表格的布局.下表列出了 Bootstrap 支持的一些表格元素: 标签 描述 <table> 为表格添加基础样式. < ...

  8. Inspect a new tab · cyrus-and/chrome-remote-interface Wiki

    Inspect a new tab · cyrus-and/chrome-remote-interface Wiki Runtime.evaluate

  9. node.js第11课(HTTPclient)

     一.http模块提供了两个函数http.request和http.get,功能是作为client向HTTPserver发起请求.     Ext.Ajax.request({},function ...

  10. win7电脑遇到端口被占用的情况该如何查看并将其关闭

    转载:http://www.jb51.net/os/windows/203315.html 端口是我们在进行远程或者打印机等都会遇到的,但是有很多用户会遇到端口被占用的情况,有很多人不知道该如何查看电 ...