-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetset.js
47 lines (39 loc) · 834 Bytes
/
getset.js
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
var Rectangle = function(height,width)
{
this.height = height ,
this.width = width ,
position = {
x : 10,
y : 20
}
printfun = function()
{
console.log("Hidden");
console.log("Height : "+ height);
console.log("Width : "+ width);
}
this.draw = function()
{
console.log("This is Function.");
printfun();
}
//Get & Set Method
Object.defineProperty(this,'position',{
get : function()
{
return position ;
},
set : function(value)
{
position = value ;
}
})
}
var ob1 = new Rectangle(3,4);
ob1.draw();
ob1.position = {
x : 100,
y : 200
}
console.log(ob1.position);
console.log(ob1.position.x);