Files
2025-02-28 13:27:28 +01:00

27 lines
596 B
JavaScript

function should(v) {
this.value = v;
}
should.prototype = {
get be() { return this; },
get ok() {
if (!this.value)
throw new Error("assertion failed");
}
};
Object.defineProperty(Object.prototype, 'should', {
get: function() { return new should(this.valueOf()); }
});
var myComplicatedPropertyDescriptor = (function(k) {
return {
[k]: function() { throw new Error("too complicated!"); }
}
})("get");
Object.defineProperty(Object.prototype, 'foo', myComplicatedPropertyDescriptor);
// OK - getters
(false).should.be.ok;
(false).should;
should.prototype.be;
({}).foo;