-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBadExampleOfThis.html
43 lines (36 loc) · 1001 Bytes
/
BadExampleOfThis.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
<!--
Demonstrates use of Trampling with Global Object
Shows how a function in which "this" is referred and when it is called without referring to an object.It affects global object
-->
<html>
<head>
<script type = "text/javascript">
//<![CDATA[
console.log("Calling default isNaN "+isNaN(NaN));
function changeisNaN(){
this.isNaN = function(){
return "If this function is called directly without creating object then it will affect default isNaN";
};
this.test= function(){
console.log("Executing test");
};
}
console.log("Changing isNaN...");
changeisNaN();
console.log("Called isNaN");
console.log("Now isNaN is "+isNaN(NaN));
/*
alert("NaN is NaN: " + isNaN(NaN));
function x() {
this.isNaN = function() {
return "not anymore!";
};
}
// alert!!! trampling the Global object!!!
x();
alert("NaN is NaN: " + isNaN(NaN));
*/
//]]>
</script>
</head>
</html>