Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript get and set availability in browsers

Which browsers do not support the get and set methods for object prototypes? I believe this is a feature of ES5, an I know it works in Chrome, but I am wondering if it is safe to use for ajax apps. Here's an example:

var foo = function () {};
foo.prototype = {
    get name () {
        return this._name;
    },
    set name (n) {
        this._name = n || "bar";
    }
};
like image 604
Adam Avatar asked May 16 '11 03:05

Adam


People also ask

What is get () in JavaScript?

The get syntax binds an object property to a function that will be called when that property is looked up.

How do you determine which browser supports a certain JavaScript feature?

The concept of feature detection The idea behind feature detection is that you can run a test to determine whether a feature is supported in the current browser, and then conditionally run code to provide an acceptable experience both in browsers that do support the feature, and browsers that don't.

How do you check which browser is being used?

In the browser's toolbar, click on “Help"or the Settings icon. Click the menu option that begins “About” and you'll see what type and version of browser you are using.

How can you detect the client's browser name in JavaScript?

Answer: To establish the actual name of the user's Web browser, you can use the navigator. appName and navigator. userAgent properties.


1 Answers

Here's a compatibility table for you.

http://kangax.github.com/es5-compat-table/

See the Getter in property initializer and Setter in property initializer rows.

According to the table:

  • Firefox 4
  • Safari 5
  • Chrome 7-11

Other browsers (including IE9) are not given a Yes or No, so perhaps they're untested. I'm pretty sure IE9 supports it.

like image 170
user113716 Avatar answered Oct 03 '22 07:10

user113716