> new jsclass();
jc.tostring();
> new jsclass();
jc.tostring();
这是javascript模拟内定义中对this的使用,这个和其它的oo语言中的情况非常的相识。但是这里要求成员属性和方法必须使用this关键字来引用,运行上面的程序会被告知myname未定义。
5、为脚本引擎内部对象添加原形方法中的this关键字:
function.prototype.getname = function()
{
var fnname = this.tostring();
fnname = fnname.substr(0, fnname.indexof('('));
fnname = fnname.replace(/^function/, '');
return fnname.replace(/(^\s+)|(\s+$)/g, '');
}
function foo(){}
alert(foo.getname());