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

  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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章