Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6379539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:09:05+00:00 2026-05-25T02:09:05+00:00

Fiddle var Assertion = function() { return { dummy: data }; } Object.defineProperty(Object.prototype, ‘should’,

  • 0

Fiddle

var Assertion = function() {
    return { "dummy": "data" };    
}

Object.defineProperty(Object.prototype, 'should', {
  set: function(){},
  get: function(){
    return new Assertion(this);
  }
});

// Insert magic here.

// This needs to be false
console.log(({}).should === undefined);

What options do I have in ES5 to undo a defineProperty call ?

No silly suggestions like Object.defineProperty = function() { } please.

The following Object.defineProperty(Object.prototype, 'should', {})

does not work

and Object.defineProperty(Object.prototype, 'should', { value: undefined })

Throws a Uncaught TypeError: Cannot redefine property: defineProperty in V8

Object.defineProperty(Object.prototype, 'should', { 
    set: function() {},
    get: function() { return undefined; }
});

Throws the same error

delete Object.prototype.should also does not work

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:09:05+00:00Added an answer on May 25, 2026 at 2:09 am

    In general, you can’t undo a defineProperty call, since there’s no undo stack or something. The JS engine does not keep track of previous attribute descriptors.

    For example,

    Object.defineProperty(Object.prototype, 'foo', {
        configurable: true,
        value: 1,
        enumerable: false
    });
    Object.defineProperty(Object.prototype, 'foo', {
        get: function () {
            alert('You cannot revert me');
            return 2;
        },
        enumerable: true
    });
    

    What you can do is remove or reconfigure an attribute, or overwrite its value. As mentioned in the other answer, the configurable flag is required to be true if you want to remove or reconfigure.
    Once a property is defined with configurable:false, you cannot change the configurable flag.


    To remove an attribute (this is supposedly what you want to do), use delete:

    Object.defineProperty(Object.prototype, 'foo', {
        configurable: true, // defaults to false
        writable: false,
        value: 1
    });
    delete Object.prototype.foo;
    console.log(Object.prototype.hasOwnProperty('foo')); // false
    

    To reconfigure, use defineProperty again and pass a different descriptor:

    Object.defineProperty(Object.prototype, 'foo', {
        configurable: true,
        get: ...
        set: ...
    });
    Object.defineProperty(Object.prototype, 'foo', {
        value: undefined
    });
    console.log({}.foo); // undefined
    console.log(Object.prototype.hasOwnProperty('foo')); // true
    

    As shown in this sample, you can use defineProperty to switch between accessor (get/set) and data (value) properties.


    To overwrite, use simple assignment. In this case, you need the writable flag to be true. Obviously this does not work with accessor properties. It even throws an exception:

    Object.defineProperty(Object.prototype, 'foo', {
        configurable: true,
        value: 1,
        writable: true // defaults to false
    });
    Object.prototype.foo = undefined;
    console.log(Object.prototype.foo); // undefined
    console.log(Object.prototype.hasOwnProperty('foo')); // true
    
    Object.defineProperty(Object.prototype, 'foo', {
        get: function () {
            return 1;
        },
        writable: true // JS error!
    });
    

    Note that writable defaults to false when you use defineProperty, but true when you use the simple syntax o.attr = val; to define a (previously not existing) property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Check out this fiddle: http://jsfiddle.net/mattball/nWWSa/ var $lis = $('ul.innerfade > li'); function fadeThemOut() {
I am doing an ajax call using jquery to get data in json format.
Please consider the following code (also in this fiddle ): var viewModel = {
I'm trying to fiddle around with this concept and I can't seem to get
I set up a fiddle with the following code: html: <div id=content> <input id=splash_button
So I tried this: var allItems = jQuery(); function additems(items) { allItems = allItems.pushStack(items);
I have the following jQuery extension: var particleTimer = 0; jQuery.fn.particleEmitter = function (num,
I have the following code: $(document).ready(function() { var $body = $(body); for (var i
I use this to get the date: var currentTime = new Date() var month
I am just starting to fiddle with Excel via C# to be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.