-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.html
92 lines (47 loc) · 1 KB
/
function.html
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
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<head>
</head>
<body>
<p id="demo"></p>
<script>
//1. anonymous self-invoking function
//2. argument property
elem_demo = document.getElementById("demo");
(function (){
elem_demo.innerHTML = "Yoo"
console.log(arguments.length);
})();
function myfun(a, b) {
return a + b;
}
//3. toString()
console.log(myfun.toString());
//4. arguments object
function findMax() {
var max = -Infinity;
var i = 0;
for (; i<arguments.length; i++) {
if(arguments[i] > max) {
max = arguments[i];
}
}
return max;
}
var m = findMax(2, 4, 11, 93, 232, 18, 892, 12);
console.log("max: ", m);
//5. call()
var person = {
firstName : "John",
lastName : "Doe",
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
var myObj = {
firstName : "Mary",
lastName : "Doe"
};
x = person.fullName.call(myObj);
elem_demo.innerHTML = x;
</script>
</body>