-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.js
50 lines (37 loc) · 1.09 KB
/
demo.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
48
49
50
// Privacy with Privileged Methods
class Animal {
constructor(name,age){
let _privateName = name;
let _privateAge = age;
let foOut = "demo";
// need a clousure to remenber the context
this.getAge = function(){
return _privateAge;
}
this.getName = function(){
return _privateName;
}
this.setAge= function(age){
_privateAge = age;
}
}
static walk(){ // no se instancia y corre!!!
// console.log(`${_privateName} is walking`);
// out of scope block scope let generate
alert("esto es auto!");
}
getForOut(){
console.log(`demo ${foOut}`);
}
caminar(){
console.log(`${this.getName()} es normal`); // var is not defined!
}
}
class Human extends Animal{
constructor(){
super("non",1);
}
}
a = new Animal(1,2);
// https://www.sitepoint.com/object-oriented-javascript-deep-dive-es6-classes/
// https://www.sitepoint.com/patterns-object-inheritance-javascript-es2015/