-
• #2
Hi - I'm afraid it doesn't support it yet... It's on my list though :)
So the issue you have is that 'this' generally gets reset when you call
setTimeout
- however you can still access any other local variables. The easiest way around it (the one that I tend to use in examples/modules) is:var sensor = this; setTimeout(function (e) { sensor.getSensorReading(); }, w);
-
• #3
Works like a charm :)
-
• #4
@d0773d, @Gordon just most recently made .bind() work / implemented... see this conversation. Now you do not need the application defined anonymous function anymore, and the .bind() is more efficient in all ways.
-
• #5
@allObjects thanks for updating my post. I will definitely impliment bind().
-
• #6
As temporary work around on top of your file:
Function.bind||(Function.prototype.bind=function(c){var f=this,a=[].slice.call(arguments,1);return function(){a.push.apply(a,arguments);return f.apply(c,a)}});
In case you don't care about handling extra arguments ...
Function.bind||(Function.prototype.bind=function(c,f){f=this;return function(){return f.apply(c,arguments)}});
Until it's solved, of course
-
• #7
Function.bind
actually exists and works fine now, so hopefully you shouldn't need to do that... -
• #8
Actually I've just realized
Function.bind
is there indeed butFunction.prototype.bind
is not ... but(function(){}).bind
is there too ... oh well, good to know (sort of weird) -
• #9
Yes, that's not right... Something strange is going on there - Thanks for letting me know.
It still works though - I think it's just the way it appears.
Hi, my question kind of relates to my question from: generic pause/wait? I'm trying to wrap my head around how prototypeing works. does the Espruino support bind? For example:
I receive error: