prototype-1.3.1.js中的bind()方法示例

来源:互联网 发布:兴国人民政府网通知 编辑:程序博客网 时间:2024/05/17 22:24
  1. <script language="javascript">
  2.     
  3.     Function.prototype.bindfunction(object){
  4.     var _method=this;
  5.     return function(){
  6.      _method.apply(object,arguments);
  7.     }
  8.     }
  9.     function class1()
  10.     {
  11.      this.attribute="class1";
  12.      this.method=function(){
  13.       alert(this.attribute);
  14.      }
  15.     }
  16.     function class2(){
  17.      
  18.     }
  19.     
  20.     class2.prototype={
  21.       attribute:"class2"
  22.      }
  23.     var obj1 = new class1();
  24.     var fun = obj1.method.bind(new class2());
  25.     fun();
  26.     
  27.   
  28.     </script>