Espruino/tests/test_settimeout_with_objects.js
2014-06-20 10:27:08 +01:00

20 lines
420 B
JavaScript

// test setTimeout with objects
var a = { cmd : "result=1;", w : "world", foo: function() { print('hello '+this.w); eval(this.cmd); } };
var hadError = false;
try {
// intentional error
setTimeout(a,100);
// used to assert fail!
} catch (e) {
print("Caught "+e);
hasError = true;
}
//setTimeout("a.foo()",100); // works
//setTimeout(a.foo,100); // shouldn't work
setTimeout(function() { a.foo(); },100);