function Sing()
{
with(arguments.callee)
alert(author + ":" + poem);
};
Sing.author = "李白";
Sing.poem = "汉家秦地月,流影照明妃。一上玉关道,天涯去不归";
Sing();
Sing.author = "李战";
Sing.poem = "日出汉家天,月落阴山前。女儿琵琶怨,已唱三千年";
Sing();
对于这段代码不理解的地方在于with(arguments.callee),分成两个部分看:1、 with() 2、arguments.callee
with(){} 它为语句设定默认对象,也就说它里面的语句可以不用再在前面加这个对象的名字了 eg:
function Sing()
{
with(arguments.callee)
alert(author + ":" + poem);
};
//等于
function Sing()
{
alert(Sing.author + ":" + Sing.poem);
};
callee 返回正被执行的 Function 对象,也就是所指定的 Function 对象的正文。
callee 属性是 arguments 对象的一个成员,它表示对函数对象本身的引用,这有利于匿名函数的递归或者保证函数的封装性。
function Sing()
{
with(arguments.callee)
alert(author + ":" + poem);
};
//等于
function Sing()
{
with(Sing)
alert(author + ":" + poem);
};