forked from nhattruongniit/learn-javascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject-creation-pattern.js
More file actions
52 lines (38 loc) · 1011 Bytes
/
object-creation-pattern.js
File metadata and controls
52 lines (38 loc) · 1011 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var obj = {
val: 5,
click: function() {
alert("hello")
}
}
function User(name, age) {
this.name = name;
this.age = age;
}
User.prototype.getName = function() {
return this.name;
}
User.prototype.getAge = function() {
return this.age;
}
var user = new User('truong', '30');
console.log(user.getName(), user.getAge());
//! Property private ====================
// Tạo cấu trúc cho đối tượng Classroom
function classRoom(students, teacher) {
// Tạo một phương thức private hiển thị sinh viên trong lớp
function get() {
console.log(students.join(','))
}
// Tạo thuộc tính đối tượng lưu trữ thông tin
this.students = students;
this.teacher = teacher;
// Gọi phương thức get
get();
// hàm nặc danh privileged
this.privil = function() {
return get;
}
}
var myClass = new classRoom(["Truong", "Chien"], "Thao");
console.log(myClass.teacher);
myClass.privil();