การใช้ Get and Set อย่างชำนาญสามารถจัดการคุณสมบัติของวัตถุโดยตรงเพื่อรับรู้การอ่านและเขียนซึ่งสามารถปรับปรุงประสิทธิภาพการเขียนโปรแกรมได้อย่างมาก
การคัดลอกรหัสมีดังนี้:
test var = {
_name: null,
_age: 0,
// อ่านและเขียน _name
ตั้งชื่อ (ชื่อ) {this._name = name;}
รับชื่อ () {return this._name;},
// อ่านและเขียน _age
ตั้งค่าอายุ (อายุ) {this._age = อายุ;},
รับ Age () {return this._age;}
-
Alert (test.name + "" + test.age); // bull 0
test.name = 'lucy';
test.age = 20;
Alert (test.name + "" + test.age); // Lucy 20