JavaScript 对象可以通过delete进行释放!
简单使用,如
n = {}; //声明了对象n
1、delete n; //ok
2、eval('delete n ') ); // ok
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Test JS delete </TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
//===================================
// 测试1
//===================================
nName = "n";
n = function(){
this.name = "n",
this.getName = function(){
alert(this.name);
}
}
alert(typeof n); // function
if(n== this[nName]){
//do nothing.
}
delete n; //true
alert(typeof n); // unknow !!! why is unknow !!!
//-->
</SCRIPT>
</HTML>
上面的这种用法,似乎产生了一些副作用。无法理解啊!!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Test JS delete </TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
//===================================
// 测试2
//===================================
nName = "n";
n = function(){
this.name = "n",
this.getName = function(){
alert(this.name);
}
}
alert(typeof n); // function
if(n == this.nName){
//do nothing
}
delete n; //true
alert(typeof n); //undefined
//-->
</SCRIPT>
</HTML>
这个 方式才真正式我要的。