mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
609 B
31 lines
609 B
11 years ago
|
/*
|
||
|
* If an Ecmascript constructor returns an object value, the value replaces
|
||
|
* the default instance created (the 'this' value that a constructor gets).
|
||
|
* This can be used to wrap the 'this' value behind a Proxy.
|
||
|
*/
|
||
|
|
||
|
/*===
|
||
|
BAR
|
||
|
===*/
|
||
|
|
||
|
function MyConstructor(x) {
|
||
|
this.foo = x;
|
||
|
return new Proxy(this, {
|
||
|
get: function (targ, key, recv) {
|
||
|
var val = targ[key];
|
||
|
return (typeof val === 'string' ? val.toUpperCase() : val);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function test() {
|
||
|
var o = new MyConstructor('bar');
|
||
|
print(o.foo);
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
test();
|
||
|
} catch (e) {
|
||
|
print(e);
|
||
|
}
|