1、Proxy代理

1、

var user={
full_name:function () {
return this.fname+" "+this.lname;
}
};
user.fname="bob";
user.lname="wood"; console.log("user.fullname:",user.full_name);

ECMAScript 6 入门之Proxy代理和set-LMLPHP

2、

var user={
full_name:function () {
return this.fname+" "+this.lname;
}
};
user.fname="bob";
user.lname="wood"; console.log("user.fullname():",user.full_name());

ECMAScript 6 入门之Proxy代理和set-LMLPHP

3、

var user=new Proxy({},{
get:function (obj,prop) {
if(prop=="full_name")
return obj.fname+' '+obj.lname;
} });
user.fname="bob";
user.lname="wood";
console.log("user.full_name:",user.full_name);
console.log("user.age:",user.age);

ECMAScript 6 入门之Proxy代理和set-LMLPHP

4、

var user=new Proxy({},{
get:function (obj,prop) {
switch (prop){
case 'full_name':
return obj.fname+' '+obj.lname; } }
// ,
// set:function (obj, prop) {
//
//
// } });
user.fname="bob";
user.lname="wood";
console.log("user.full_name:",user.full_name);
console.log("user.age:",user.age);

ECMAScript 6 入门之Proxy代理和set-LMLPHP

var user=new Proxy({},{
get:function (obj,prop) {
switch (prop){
case 'full_name':
return obj.fname+' '+obj.lname; } }
,
set:function (obj, prop) { } });
user.fname="bob";
user.lname="wood";
console.log("user.full_name:",user.full_name);
console.log("user.age:",user.age);

2、Set

var arr=[1,2,3,3];
console.log("arr:",arr);
var s=new Set([1,2,3,3]);
console.log("s:",s);
console.log("s.sise:",s.size);
s.add(4);
console.log("s:",s);
s.delete(2);
console.log("s:",s);
console.log("s.has(5):",s.has(5));
console.log("s.has(3):",s.has(3));
s.clear();
console.log("s:",s);

ECMAScript 6 入门之Proxy代理和set-LMLPHP

04-11 07:03