Unspecified Error.call

# David Bruant (13 years ago)

I've recently discovered that the following code seems to have an undefined behavior in ES5.1

var o = {}; Error.call(o, 'ya'); // what is the "Error" function supposed to do with 'this', who knows? console.log(o.message) // undefined in latest Firefox, Chrome and Opera

The result seems consistent across browsers I could test with. Maybe I'm misreading the spec?

# Jussi Kalliokoski (13 years ago)

I would expect that since Error works without new, it would disregard this, hence that call would just return a new Error, so:

Error.call(o, 'ya') instanceof Error // true

# David Bruant (13 years ago)

Le 24/07/2012 17:40, Jussi Kalliokoski a écrit :

I would expect that since Error works without new, it would disregard this, hence that call would just return a new Error, so:

Error.call(o, 'ya') instanceof Error // true ... true.

Error.call(o, 'ya').message === 'ya';

My bad.