forked from codesONLY/JavaScriptONLY
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.js
More file actions
48 lines (34 loc) · 804 Bytes
/
Copy pathproperties.js
File metadata and controls
48 lines (34 loc) · 804 Bytes
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
44
45
46
47
48
function sayHi() {
console.log("Hi");
}
console.log(sayHi.name);
console.log(function () {}.name); // empty string
function f1(a) {}
function f2(a, b) {}
function many(a, b, ...more) {}
console.log(f1.length); // 1
console.log(f2.length); // 2
console.log(many.length); // 2
// custom property
function sayHi() {
console.log("Hi");
// let's count how many times we run
sayHi.counter++;
}
sayHi.counter = 0; // initial value
sayHi(); // Hi
sayHi(); // Hi
console.log(`Called ${sayHi.counter} times`); // Called 2 times
// counter with custom property
function makeCounter() {
// instead of:
// let count = 0
function counter() {
return counter.count++;
}
counter.count = 0;
return counter;
}
let counter = makeCounter();
alert(counter()); // 0
alert(counter()); // 1