拿来OO的吧?比如这样:
<script>
function a(){
var str;
str="abc";
this.b=function(){
alert(str);
}
}
var o=new a()
o.b()
</script>
但单独像你给的代码那样使用,我还真的没有用过,考虑考虑先。
<script>
function a(){
var str;
str="abc";
this.b=function(){
alert(str);
}
}
var o=new a()
o.b()
</script>
但单独像你给的代码那样使用,我还真的没有用过,考虑考虑先。
好象的确是这样……
var str;
str="abc"
function b(){
alert(str);
}
}想执行b用a.b();
代码拷贝过去后,运行良好,自己增加功能的时候发现“少”一个“}”,加上去就出错,才发现了这个“秘密”
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( );