-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest3.ts
43 lines (34 loc) · 1.03 KB
/
test3.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Test {
export class test3 {
public constructor() {
}
public start(): void {
var fn2_1T: number = egret.getTimer();
this.Fn2_1(50000);
console.log(egret.getTimer() - fn2_1T);//耗时:54
var fn2_2T: number = egret.getTimer();
this.Fn2_2(50000);
console.log(egret.getTimer() - fn2_2T);//耗时:30
}
private a: number = 1;
private b: number = 1;
private Fn2_1(n: number): number//直接调用this
{
for (var i: number = 3; i <= n; i++) {
this.b = this.a + this.b;
this.a = this.b - this.a;
}
return this.b;
}
private Fn2_2(n: number): number//先赋值作用域变量
{
var a: number = this.a;
var b: number = this.b;
for (var i: number = 3; i <= n; i++) {
b = a + b;
a = b - a;
}
return b;
}
}
}