---
title: "关于with(arguments.callee)"
author: "starnc"
date: "2010-11-16T15:39:10Z"
tags: []
categories: ["Web前端"]
slug: "with-arguments-callee"
draft: false
lastmod: "2010-11-16T15:57:10Z"
id: 812881
url: "https://starnc.iteye.com/blog/812881"
---

```js
    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：


```js
   function Sing()
    {
        with(arguments.callee)
          alert(author + &quot;：&quot; + poem);
    };

    //等于

    function Sing()
    {
          alert(Sing.author + &quot;：&quot; + Sing.poem);
    };

```

 

 
    callee 返回正被执行的 Function 对象，也就是所指定的 Function 对象的正文。 

    callee 属性是 arguments 对象的一个成员，它表示对函数对象本身的引用，这有利于匿名函数的递归或者保证函数的封装性。


        



```js
    function Sing()
    {
        with(arguments.callee)
          alert(author + &quot;：&quot; + poem);
    };
    //等于

     function Sing()
    {
        with(Sing)
          alert(author + &quot;：&quot; + poem);
    };

```