Redefine Object.defineProperty in Javascript

Posted by kwicher on Stack Overflow See other posts from Stack Overflow or by kwicher
Published on 2013-11-07T01:22:38Z Indexed on 2013/11/07 3:54 UTC
Read the original article Hit count: 108

Filed under:
|
|

I would like to learn if it is possible to redefine the "definePropery" function of the Object(.prototype) in a subclass(.prototype) so that the setter not only sets the value of the property but also eg executes an additional method.

I have tried something like that:

Myclass.prototype.defineProperty = function (obj, prop, meth) {
    Object.defineProperty.call(this, obj, prop, {
        get: function () {
            return obj[prop]
        },
        set: function () {
            obj[prop] = n;
            alert("dev")
        }
    })
}

But id does not work

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about prototype