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 7846111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:28:06+00:00 2026-06-02T17:28:06+00:00

Asking about Object.defineProperty as demonstrated below: function testComponent(){ var testProperty; Object.defineProperty(this, testProperty, { get

  • 0

Asking about Object.defineProperty as demonstrated below:

function testComponent(){
    var testProperty;
    Object.defineProperty(this, "testProperty",
    {
        get : function()
        {
           return testProperty;
        },
        set : function(val)
        {
          testProperty = val;
        }
    });
}

Where it would be used like so:

testObject = new testComponent();
testObject.testProperty = "testValue";

Based on what I’ve seen so far, it looks like there is no cross browser solution, as I’ve tried using es5-shim with no luck, but I would like to confirm. I also found a reference to this post and my tests still fail in IE 7 & 8, can anyone shed any light on this?

I remember looking through a related question a few months ago somewhere on S/O and I think I saw someone had written a solution for this in an answer. Any general workarounds for getter / setters would also be appreciated. The idea is that I need some equivalent of a getter setter on an object without passing the parameter change through a method. I don’t need IE6, but I would like to support browsers in the range of IE7+ ff 3.6+ , etc


QUnit tests below: (jsFiddles)

(these pass in all browsers on my machine except IE 7 & 8

direct use of defineProperty, no shims:
http://jsfiddle.net/uSYFE/

fiddle using the ES5 shim, I’m assuming all I need to do is include it? :
http://jsfiddle.net/hyperthalamus/ntwDy/

fiddle using the IE recommended solution :
http://jsfiddle.net/hyperthalamus/xfvz3/

  • 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-06-02T17:28:07+00:00Added an answer on June 2, 2026 at 5:28 pm

    According to ES5-shim:

    /!\ Object.defineProperty

    This method will silently fail to set "writable", "enumerable", and "configurable" properties.

    Providing a getter or setter with "get" or "set" on a descriptor will silently fail on engines that lack "defineGetter" and "defineSetter", which include all versions of IE up to version 8 so far.

    IE 8 provides a version of this method but it only works on DOM objects. Thus, the shim will not get installed and attempts to set "value" properties will fail silently on non-DOM objects.

    https://github.com/kriskowal/es5-shim/issues#issue/5

    So you know your answer. It can be done on DOM elements, that’s it (and on IE8 only).

    I’d suggest you just use get/set methods if you want IE7 to work.

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

Sidebar

Related Questions

I am specifically asking about this paragraph in the Android documentation: If the object
Inspired by another question asking about the missing Zip function: Why is there no
I saw this question asking about whether globals are bad . As I thought
I am asking about the static binding of the function in C++. What's the
When a function is attached to an object and called: function f() { return
I'm not asking about WHEN to link different programming langauges. This is quite a
Not sure if I am asking this correctly (e.g. using widget/object in the correct
I know that this might be a duplicate of: Return a "NULL" object if
When asking about common undefined behavior in C , people sometimes refer to the
I'm not really asking about how programmers learn how to program. More about specific

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.