<script>Function.prototype.method=function B(name)
{
    alert('BEGIN');
    this.prototype.faint=name;
    alert('END');
};
function Person()
{
}
function User()
{
}
//Person.sMethod=B(name);
//Person.sMethod('KAO');
Person.method('KAO');
alert(new Person().faint);</script>
这段能正常输出 BEGIN,END,KAO为什么我换成
<script>Function.prototype.method=function B(name)
{
    alert('BEGIN');
    this.prototype.faint=name;
    alert('END');
};
function Person()
{
}
function User()
{
}
Person.sMethod=B(name);
Person.sMethod('KAO');alert(new Person().faint);</script>
就只能输出个BEGIN?那B函数中的this应该一直是指向调用者Person的啊?请问为什么

解决方案 »

  1.   

    <script> 
    Person.sMethod=B(name); 
    Person.sMethod('KAO'); 

    Function.prototype.method=function B(name) 

        alert('BEGIN'); 
        this.prototype.faint=name; 
        alert('END'); 
    }; 
    function Person() 


    function User() 

    } alert(new Person().faint); </script> 
      

  2.   

    <script> function B(name) 

        alert('BEGIN'); 
        this.prototype.faint=name; 
        alert('END'); 
    }; 
    function Person() 


    function User() 


    Function.prototype.method=B(name) ;
    Person.sMethod=B(name); 
    Person.sMethod('KAO'); alert(new Person().faint); </script> 
      

  3.   

    很明显第2个指到window上去
    this 指向调用他的对象
    Person.sMethod=B(name); 
    直接执行的B(name);  何来对象调用B  当然指向windowtestvar xx = 'xxxxxxxxxx';
    Function.prototype.method=function B(name) 

        alert('BEGIN'); 
        alert(this.xx);  //test 是不是指到window
    this.prototype.faint=name;  //报告错误了 自然不会往下执行
        alert('END'); 
    }; 
    function Person() 


    function User() 


    Person.sMethod=B(name); 
    Person.sMethod('KAO'); alert(new Person().faint); 
      

  4.   

    Person.sMethod=B(name); ==============>>>>>  Person.sMethod=function(name){B.call(Person,name);}