You can call normal functions or constructor functions like this:
fun.apply(this);
fun.call(this);
fun.bind(this); fun();
but if function is DOM object constructor function, how do you call it remotely and pass this
.
One example would be XMLhttpRequest
.
Make it work like XMLhttpRequest.apply(etc);
I am trying to make constructor function that not only initialize a new object with Dom Object Constructor but also add extra stuff that i want it to have.
for example:
function myxmlhttpfunc () {
this = new XMLhttpRequest();
this.myprop = 'etc';
}
But as you can try or see 2nd line wont work, i tried using apply,call,bind. Only way to get it do that is return new XMLhttpRequest();
which overrides myprop
. If there is a way to execute multiple statements at return i'd appreciate it. I am even considering calling settimeout, but trying to avoid it. What i'd do is pass this as a reference to time out once its initialized by return then define new properties as i like.