<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的啊?请问为什么
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>
{
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>
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);