-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hello ExtensionMethod.js.html
44 lines (35 loc) · 1.34 KB
/
Hello ExtensionMethod.js.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
<html>
<head>
<title>Understanding ExtensionMethod.js</title>
</head>
<body>
<script src="src/ExtensionMethod.js"> </script>
<script>
var Person = function (first, last, age) {
this.firstName = first;
this.lastName = last;
this.age = age;
}
var person = {
"firstName" : "Satish",
"lastName" : "Yadav",
};
// Adding an extension method to any object of type Person
// Method name will be "SayMyName"
// The method body of SayMyName is defined as third parameter
new ExtensionMethod()
.Add(Person, "SayMyName", function () {
console.log("Extension Method called. First Name: " + this.firstName + " and Last Name: " + this.lastName);
alert("Extension Method called. First Name: " + this.firstName + " and Last Name: " + this.lastName);
});
new ExtensionMethod()
.Add(person, "SayMyName", function () {
console.log("Extension Method called. First Name: " + this.firstName + " and Last Name: " + this.lastName);
alert("Extension Method called. First Name: " + this.firstName + " and Last Name: " + this.lastName);
});
var x = new Person("S", "Y", 10);
x.SayMyName();
person.SayMyName();
</script>
</body>
</html>