六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 40|回复: 0

prototype中的bind方法

[复制链接]

升级  13.33%

18

主题

18

主题

18

主题

秀才

Rank: 2

积分
70
 楼主| 发表于 2013-1-27 05:14:58 | 显示全部楼层 |阅读模式
<script type="text/javascript" src="prototype_mini.js" ></script><script>var Cat = Class.create();Cat.prototype = {initialize:function(name){this.name = name;},show:function(){alert('show!!!');}}var Dog = Class.create();Dog.prototype = {initialize:function(name){this.name = name;},run:function(){alert("run!!!");}}var cat1 = new Cat("cat1");cat1.show();var dog1 = new Dog();run1 = dog1.run.bind(cat1);run1();show2 = cat1.show.bind(dog1);show2();function a(a,b){alert("a method invoked!!!"+(a+b));}function c(){}function b(){var a = 0;}var b1 = new b();a.apply(b1,[1,2]);//b1继承了a的所有方法和属性c.call(b1,1,2);//这样也能调用?</script>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表