[Javascript] Prototype 1
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的更多相关文章
- [原创]javascript prototype 对象 函数 <精简的美丽......>
精简的美丽...... javascript prototype 对象 函数 在javascript中我们都知道创建一个对象使用如下代码var x = {}对象可以拥有属性和方法var x = { ...
- javascript prototype原型链的原理
javascript prototype原型链的原理 说到prototype,就不得不先说下new的过程. 我们先看看这样一段代码: <script type="text/javasc ...
- JavaScript Prototype in Plain Language
非常好的文章: http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/ jan. 25 2013 14 ...
- JavaScript prototype原型用法
JavaScript对象原型 所有JavaScript对象都从原型继承属性和方法. <!DOCTYPE html> <html> <meta charset=" ...
- illustrating javascript prototype & prototype chain
illustrating javascript prototype & prototype chain 图解 js 原型和原型链 proto & prototype func; // ...
- HTML 学习笔记 JavaScript (prototype)
原博地址:http://www.cnblogs.com/dolphinX/p/3286177.html 原博客的作者是一个非常牛逼的前端大神,我作为一个初学者,在此借助大神的博客进行自己的学习.在这里 ...
- 关于 JavaScript prototype __proto__ 一点总结
http://www.cnblogs.com/wbin91/p/5265163.html 先上代码 function(y) Foo{ this.y = y;} Foo.prototype.x = 10 ...
- JavaScript prototype 使用介绍
用过JavaScript的同学们肯定都对prototype如雷贯耳,但是这究竟是个什么东西却让初学者莫衷一是,只知道函数都会有一个prototype属性,可以为其添加函数供实例访问,其它的就不清楚了, ...
- JavaScript——Prototype详探
用过JavaScript的同学们肯定都对prototype如雷贯耳,但是这究竟是个什么东西却让初学者莫衷一是,只知道函数都会有一个prototype属性,可以为其添加函数供实例访问,其它的就不清楚了, ...
- JavaScript prototype应用
//JavaScript自定义功能 //1,去除字符串两端空格 String.prototype.trim = function() { var start, end; start = 0; end ...
随机推荐
- android 定时, 延时 任务
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 倒计时类 用 倒计时定时器CountDownTimer 延迟类 CountDownT ...
- Kali2.0通过xrdp实现windows远程链接Linux
标题:Kali2.0通过xrdp实现windows远程链接Linux apt-get install xrdp 首先需要安装xrdp 接下来安装xfce4 apt-get install xfce4 ...
- zookeeper【3】服务发现
服务发现:指对集群中的服务上下线做统一管理,每个工作服务器都可以作为数据的发布方,向集群注册自己的基本信息,而让某些监控服务器作为订阅方,订阅工作服务器的基本信息.当工作服务器的基本信息改变时,如服务 ...
- [LeetCode] Max Points on a Line 题解
题意 Given n points on a 2D plane, find the maximum number of points that lie on the same straight lin ...
- CentOS6.X关闭防火墙
一.关闭防火墙 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2.即时生效,重启后失效: 开启:service ipta ...
- 如何编写LVS对Real Server的健康状态检测脚本
简介:Linux 虚拟服务器(Linux Virtual Server. LVS),是一个由章文松开发的自由软件.利用KVS可以实现高可用的.可伸缩缩的Web, Mail, Cache和Medial等 ...
- 全栈project师体能备战--知识面(1--10)
javascript 单例设计模式: 单例模式确保某个类仅仅有一个势力,并且自行实例化并向整个系统提供这个实例.如:cocos2dx中的导演类.[样例]我有6哥美丽的老婆,他们的老公都 ...
- STM32学习笔记3-IO配置输入输出
STM32的IO配置时没什么特殊的,有个注意点就是有用IO前须要先打开其时钟线,下面是验证过oK的程序: RCC->APB2ENR|=GpioBApb2enrEn; //使能PORTB时钟 GP ...
- IoC Containers with Xamarin
When writing cross platform apps with Xamarin, our goal is share as close to 100% of our code across ...
- C#关键字var是什么,在何种情况下使用
从.NET 3.0开始,在方法内部可以使用var关键字声明局部变量.var关键字到底是什么?在何种情况下使用呢? □ var关键字用来隐式地声明一个数据类型,变量类型是在编译期确定的,而不是在运行时确 ...