-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.adding_methods_to_objects.html
More file actions
31 lines (27 loc) · 966 Bytes
/
15.adding_methods_to_objects.html
File metadata and controls
31 lines (27 loc) · 966 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
<html>
<head>
<script type="text/javascript">
// creating my own object
function person(name, age)
{
this.name = name // seems to be like python self
this.age = age
this.years_until_retire = years_left // Note: We don't add parenthesis
}
function years_left()
{
var num_years = 65 - this.age
return num_years
}
// I think this is like constructor
var prasad = new person("Prasad Dalavi", 24) // similar to jave instance creation
var pranit = new person("Pranit Dalavi", 19)
</script>
</head>
<body>
<script type="text/javascript"> // I am writing this javascipt for the second time.
document.write(prasad.years_until_retire(), "<br />") // 41 calling the properties/methods of object
document.write(pranit.years_until_retire()) //46
</script>
</body>
</html>