var  vvv = "1";
function cc(){
var vv = "1"; 
function xx(){

}
alert(xx.__parent__);
alert(xx.__parent__ === cc.__parent__);
}
alert(cc.__parent__);
cc();
第一个弹出来的是window  这个好理解 cc是全局的 作用域在window下
但是第2个xx 还是winow, xx的作用域不是在cc里面了吗 为何window  alert(xx.__parent__ === cc.__parent__);为 true

解决方案 »

  1.   

     this.xx=function(){
            
        }
      

  2.   


    var  vvv = "1";
    function cc(){
        var vv = "1"; 
        function xx(){
            
        }
    alert(this==window)
        alert(xx.__parent__);
        alert(xx.__parent__ === cc.__parent__);
    }
    alert(this==window)
    alert(cc.__parent__);
    cc();
      

  3.   

    不对噢
    this只是指向他的对象  与定义作用域无关吧
      

  4.   

    var  vvv = "1";
    (function(){
    alert(this===window)  //true
    function cc(){
    var vv = "1";
    function xx(){
    alert(xx.__parent__ === cc.__parent__);
    }
    }
    alert(cc.__parent__);  //null
    })();
      

  5.   

    因为 "undefined" === "undefined"
      

  6.   

    请用firefox测试
    ie下无法访问__parent__属性...........
      

  7.   

    没有被this之类关联的变量作用域都是window下啊
    全局和非全局 只是影响可见范围 和作用域应该没关系吧
    个人理解
      

  8.   

    路过学习
    个人还第一次见到这种function套用法
    顶下
      

  9.   

    js 中的函数都可以看作一个对象,函数都是继承Object的,应该是由于这一点,上面的cc.parent===xx.parent;
      

  10.   

    o,楼主的写轮眼很帅,很喜欢 HOHO
      

  11.   

    你说的不对哦函数是可以看成一个对象   但是他是先继承的Function的prototype 然后在是继承到Object的prototyeObject.prototype.a="a";
    Function.prototype.a="aa";
    function xx(){}
    alert(xx.a)
    delete Function.prototype.a
    alert(xx.a)另外 是__parent__属性  不是 parent属性
    这个属性 很特殊(函数的[[scope]] 属性,不访问,在firefox下提供__parent__属性来访问) 它引用的是函数定义时的作用域链
    这个与继承什么的无关  只与函数定义时候的作用域有关 ps:这个眼睛是卡卡西 或者说是带土的眼睛     不是鼬或者zz的
      

  12.   

    The JavaScript language does not provide you with a method of accessing a function’s Variable object. The only way to access this object is by taking advantage of the __parent__ magic property. For example, the following script (which works in Firefox) returns the Global scope object:   1:  <script type="text/javascript">   2:      3:  function doSomething() {}   4:      5:  alert(doSomething.__parent__); // returns Window   6:      7:  </script>   8:   The Global scope object in the case of a browser is the Window object. All global variables become properties of the Window object.Unfortunately, the __parent__ property does not work with nested functions when used with Firefox (SpiderMonkey). When __parent__ is used with Firefox, it always returns either the Window object or null. If you want to use __parent__ with nested functions, then you need to use Rhino.Rhino is the Java version of the Mozilla JavaScript engine. You can download Rhino from http://developer.mozilla.org/en/docs/Rhino. To get Rhino to work in Windows, I had to follow the instructions from the following blog entry by Luke Maciak: http://www.terminally-incoherent.com/blog/2008/01/08/rhino-scripting-java-with-javascript.After Rhino is setup, you can execute JavaScript statements from the command line. I executed the following commands:   1:  function f()    2:      3:  {   4:      5:    var bob='hello';   6:      7:    var inner = function(){};    8:      9:    var parent = inner.__parent__;   10:     11:    var contents = '';   12:     13:    for (k in parent) contents += k + ' ';   14:     15:      print(contents);   16:     17:  }  18:     19:  f();The script above contains a function named f(). This function contains an inner function named inner. The __parent__ property of the inner function returns f’s Variable object. Therefore, when the script is executed, the following list of items is printed:    arguments bob contents parent innerThese are the properties that you would expect for the f function’s Variable object. The first items, represents the parameters passed to the f() function. The remaining items correspond to each of the f() function’s local variables.
      

  13.   

    Unfortunately, the __parent__ property does not work with nested functions when used with Firefox (SpiderMonkey). When __parent__ is used with Firefox, it always returns either the Window object or null.
      

  14.   

    这个看的不是很懂
    但你想表达的意思是说 firefox下 调用函数的__parent__属性 总是返回window or null
    那为什么
    var  vvv = "1";
    function cc(){
        var vv = "1"; 
        function xx(){
            
        }
        alert(xx.__parent__);  //这里不是返回的 null了.........
        alert(xx.__parent__ === cc.__parent__);
    }
    alert(cc.__parent__);
    cc();
      

  15.   

    就是FF下的__parent__不能在嵌套函数中正确的执行,你问为什么那里不是返回null,那我也想知道,你为什么认为那里应该返回null。在FF下测试的前提已经不对了,所以,不需要继续问这个问题了,你自己知道那里的scope object是什么就可以了,如果一定要测试,可以按#14楼的方法,到Rhino下去测试。