- Joined
- Jun 8, 2007
- Messages
- 1,965
- Reaction score
- 482
Here's a challenge for you:
Figure out what this library does:
(Library: )
. . .
(Implementation: )
Console Output:
(Note: You can try this in a good, modern browser that supports console.log for development purposes, by surrounding the code in "<script> .. </script>" tags.)
Kudos to people who can figure it out, and these are released under the BSD license- enjoy.
Figure out what this library does:
(Library: )
PHP:
var waject = function(o, Preset, Got) {
"use strict";
o = Object.create(o || null);
var item, Main = {}, $ = function (property, value) {
Object.defineProperty(Main, property, {value: value});
};
$('mk', function (props, val, preset, got) {
var nil = function () {}, prop = (
props.property || props
);
Object.defineProperty(Main, prop, {
get: function () {
if ((props.got
|| got
|| Got
|| nil
)(o, prop) !== false) {
return o[prop];
}
},
set: function (value) {
if((props.preset
|| preset
|| Preset
|| nil
)(o, prop, value) !== false) {
return o[prop] = value;
}
},
configurable: true,
enumerable: true
});
o[prop] = (props.value || val || null);
});
$('toString', function () {
return JSON.stringify(o, null, '\t');
});
for (item in o) {
if (typeof o[item] === "object") {
Main.mk(item, waject(o[item], Preset, Got));
} else {
Main.mk(item, o[item]);
}
}
o.toString = Main.toString;
return Main;
};
. . .
(Implementation: )
PHP:
(function (waject) {
"use strict";
var o = waject({
a: 1,
b: 2,
c: {
d: 3,
e: 4
}
}, function (obj, property, val) {
console.log(property
+ " change from "
+ obj[property]
+ " to: "
+ val
);
});
o.c.d += o.a * o.b;
console.log("o: " + o);
}(waject));
Console Output:
Code:
d change from 3 to: 5
o: {
"a": 1,
"b": 2,
"c": {
"d": 5,
"e": 4
}
}
(Note: You can try this in a good, modern browser that supports console.log for development purposes, by surrounding the code in "<script> .. </script>" tags.)
Kudos to people who can figure it out, and these are released under the BSD license- enjoy.
Last edited:

