javasript函数和对象理解
function Complex(real,imageInaery){ this.r=real; this.i=imageInaery; } var com = new Complex(1,3); //javascipt类和对象都是用function来定义,不同的是初始化对象 new console.log(com.i); console.log(com.r);
javascript 中的闭包:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script>
function f1(){
var i=990;
function f2(){
console.log(i++);
}
return f2;
}
s=f1();
s();
</script>
</head>
<body>
</body>
</html>
闭包:定义的变量 i 在调用f1函数后不会立即销毁,因为f2()还需要他,所以多次调用S()后局部变量i会不停的叠加。
prototype 理解:没加就是静态函数,加了就是类函数。

浙公网安备 33010602011771号