Posts

Showing posts with the label define

Object.prototype.define Proposal

Somebody may think that defineProperties is boring and I kinda agree on that. The good news is that JavaScript is flexible enough to let you decide how to do that ... and here I am with a simple proposal that does not hurt, but can make life easier and more intuitive in modern JS environments. Unobtrusive Object.prototype.define How To Well, the handy way you expect. The method returns the object itself, so it is possible to define one or more property runtime and chain different kind of definitions, as example splitting properties from method and protected properties from protected methods. var o = {}.define("test", "OK"); o.test; // OK Multiple properties can share same defaults: var o = {}.define(["name", "_name"], "unknown"); o.a; // unknown o._a; // unknown Methods are immutable by default and properties or methods prefixed with an underscore are by default not enumerable. function Person() {} Person.protoype.define( ["getN...