Coming from a class-based OOP background (C++/Java/C#), I'm on the path of learning object-oriented JavaScript. I often read advice about using Object.create(...)
instead of new ...
when dealing with objects is JS.
So I tried to create AJAX calls that way :
var req = Object.create(XMLHttpRequest);
req.open(...); // TypeError: req.open is not a function
Shouldn't open
be in req
's prototype chain ?
I also tried to apply the XMLHttpRequest
constructor function to my object :
var req = Object.create(XMLHttpRequest);
XMLHttpRequest.apply(req, null); // Constructor XMLHttpRequest requires 'new'
Just when I thought I was out of trouble with JS's OO way, this pulls me back in :)
Many thanks to those who'll help me understand what's going on here.