MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See for all notifications.

Your Search Results


    This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

    This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.


    The __defineGetter__ method binds an object's property to a function to be called when that property is looked up.


    obj.__defineGetter__(prop, func)


    A string containing the name of the property to bind to the given function.
    A function to be bound to a lookup of the specified property.


    The __defineGetter__ allows a getter to be defined on a pre-existing object.


    // Non-standard and deprecated way
    var o = {};
    o.__defineGetter__('gimmeFive', function() { return 5; });
    console.log(o.gimmeFive); // 5
    // Standard-compliant ways
    // Using the get operator
    var o = { get gimmeFive() { return 5; } };
    console.log(o.gimmeFive); // 5
    // Using Object.defineProperty
    var o = {};
    Object.defineProperty(o, 'gimmeFive', {
      get: function() {
        return 5;
    console.log(o.gimmeFive); // 5


    Not part of any specifications.

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support (Yes) (Yes) 11 (Yes) (Yes)
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support (Yes) (Yes) (Yes) ? (Yes) (Yes)

    See also

    Document Tags and Contributors

    Last updated by: arai,