拿来OO的吧?比如这样:
<script>
function a(){
var str;
str="abc";
this.b=function(){
alert(str);
}
}
var o=new a()
o.b()
</script>
但单独像你给的代码那样使用,我还真的没有用过,考虑考虑先。

解决方案 »

  1.   

    模拟Private?呵呵。
    好象的确是这样……
      

  2.   

    function a(){
    var str;
    str="abc"
    function b(){
    alert(str);
    }
    }想执行b用a.b();
      

  3.   

    我是从灰豆宝宝.net的层拖动代码中发现的http://community.csdn.net/Expert/topic/3088/3088242.xml?temp=.2058527
    代码拷贝过去后,运行良好,自己增加功能的时候发现“少”一个“}”,加上去就出错,才发现了这个“秘密”
      

  4.   

    少看了一句 只有NS6支持
    function myFuncA( ) {
        var valueA = "A";
        myFuncB( );
        function myFuncB( ) {
            var valueB = "B";
            alert(valueB);
            alert(valueA);
        }
    }
    When you invoke myFuncA( ) from the global space, it invokes its nested function, which dutifully displays the values of the two variables that are defined in the outer and inner functions. IE behaves the same way, as expected. But in Netscape 6 or later, you can invoke the nested function from the global space by way of the outer function: myFuncA.myFuncB( );
      

  5.   

    myFuncB在IE中不能直接调用,无论是myFuncA.myFuncB( )还是myFuncB( )都是缺少对象myFuncB在NS(我是7.0 pr1)中可通过myFuncA.myFuncB()直接调用,valueA值为undefined
      

  6.   

    我觉得js把function和类混淆了。
      

  7.   

    js没有类的概念,它所有的东西都是对象,所以jscript帮助里说它是一种“基于”对象的语言