Take the 2-minute tour ×

I've noticed that in ECMAScript standards you have things like defineProperty, which is like defining properties and what not in a JavaScript object and prototype which extends the objects by use of methods and what-not. Is there a shorthand that could take you from:

    type : "string",
    get : function(){ return this.$d.name; },
    set : function(_v){ this.$d.name = _v }

to something as simple as this:

function Person(args){
// ... snip ...

   get : function() { return $d.name },
   set : function(_v) { $d.name = _v; },
   type : "string"

// ... snip ...

I'm pretty sure that with the magic of JavaScript that there's a simpler way. But I might be just lazy. Any pointers?

NOTE: I'm avoiding the use of CoffeeScript, it's too much of a reminder of Ruby, IMHO.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can augment Object.prototype to achieve this:

Object.defineProperty( Object.prototype, "defineProperty", {
    value: function( name, pd ) {
        return Object.defineProperty( this, name, pd );

    enumerable: false
share|improve this answer
You're preventing the normal use of Object.defineProperty with this. –  Paul S. Sep 7 '12 at 21:16
@shhac How so? Object.defineProperty is untouched. –  Esailija Sep 7 '12 at 21:17
Nevermind, you are correct +1 –  Paul S. Sep 7 '12 at 21:20
add comment

Your Answer


