Javascript Object.defineProperty produces a TypeError in FireFox 19.02 (MacOS)
Asked Answered
B

1

4

Just today I tried to include an older library of mine that uses the Object.defineProperty() method in javascript into an HTML document. I am quite certain that in previous versions of FireFox it worked just fine. However, if I use it now, in FF 19.02 on MaxOS 10.6.8, as in this example:

var nuArray = function (values) {
    for (var i in values) {this[i] = values[i]}
}
nuArray.prototype = Array.prototype;

var defaultProperties = {configurable: true, writable: true, enumerable: false, get: undefined, set: undefined, value: undefined};

Object.defineProperty(nuArray, "grep", defaultProperties)

I get the following error

TypeError: property descriptors must not specify a value or be writable when a getter or setter has been specified @ ....

I added the value, get and set parts only later to set them explicitly to undefined (they should be by default, but since this behaviour was rather strange to start with, I wanted to make sure I had every base covered). It runs without a problem in Safari 5.1.7 and, as I already mentioned before, I am very sure it did so in a previous version of FF. Strangely enough, even now, if I just copy the lines of code into the console of FF, no error is thrown either and everything works as it should. It doesn't make any difference if I define value, get or set. Is there anything blatantly obvious that I am overlooking or am I running into a new issue of browser-incompatibility here?

Broadminded answered 11/4, 2013 at 15:32 Comment(1)
problem still persists in FF 20.0.Broadminded
D
8

Inside a property descriptor, leave out the 'writable' property when using properties 'set' or 'get'.

Dneprodzerzhinsk answered 27/12, 2015 at 8:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.