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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:00:48+00:00 2026-06-09T13:00:48+00:00

I need to make a change but continue providing backwards-compatibility for some time, but

  • 0

I need to make a change but continue providing backwards-compatibility for some time, but I can’t figure out how to accomplish this.

I have an Object like this:

MyObject = (function() {
   // vars here and there

   var myVar

   // a bunch of code

   return {
     get myVar() { return myVar },
     myVar: function() { return myVar }
   }

}())

This doesn’t work. I want to be able to get myVar both with

MyObject.myVar

and

MyObject.myVar()

Is it possible? Even better, is there any possibility to accomplish that and make it cross-browser compatible? (Right now I know the get notation is not supported by Internet Explorer)

Thanks.

UPDATE:

Because it seems not possible, is there any way to make what I have now, get myVar() browser-compatible with Internet Explorer?
So all browsers can access MyObject.myVar

As long as I can continue providing a getter to myVar and it’s compatible with Internet Explorer, there is no need to move to myVar() but I couldn’t find a feasible solution to make the current way (MyObject.myVar) compatible other than moving to a function-like getter.

  • 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-09T13:00:49+00:00Added an answer on June 9, 2026 at 1:00 pm

    It IS possible, though your code will look rather nasty. Since functions are objects, they have a valueOf property, too. Exploit that by overriding it with a reference to the method itself, and you’re there:

    var foo = (function()
    {
        var bar = 'foobar';
        var r = {
            bar:function()
            {
                return bar;
            }
        };
        r.bar.toString = r.bar.valueOf = r.bar;//valueOf && toString invoke the method
        return r;
     })();
    

    Be advised, its type will be an object all the same, so strict comparisons won’t work:

    foo.bar =='foobar'//true
    foo.bar === 'foobar'//false
    alert(foo.bar+'');//alerts foobar
    alert(foo.bar);//alerts foobar now, setting toString to reference the method, too
    console.log(foo.bar());//foobar <= still works, and here strict comparisons do work
    

    This can cause lots of nasty bugs that could leave you scratching your hair for up to the point there’s no hair left to scratch. Not to mention other people that might end up maintaining your code!

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

Sidebar

Related Questions

I need to make javascript code to swap images with option change. Here is
I have 3 buttons to change language. So I need to make method, where
I need to make some changes to an old Oracle stored procedure on an
I am C++ programmer and I need to make some changes to VB6 code.
I have an excel file that I need to make some changes. I need
I need to download file from FTP server and make some changes on it
Even .head doesn't work. What changes do I need to make to make this
I need make some action (dump statistical data) before the Dart program ends. The
At work I use ClearCase and SourceSafe, but have found some time to do
We use a customized installation of SugarCRM and I need to make a change

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.