Reputation: 2392
This will be an easy question for someone, typescript doesn't like the below syntax, how do I rewrite it using jQuery 'on'?
var funcA= "FuncA('" +id+ "'," +max+ ");";
$textbox[0].onkeyup = new Function(funcA));
I could possibly pass id and max in a closure but I'd like to know how to use 'Function' with the jQuery 'on' function
It would also be useful to know if it's possible to specify a region in typescript as ignorable, to be able to say just treat this block as valid javascript
Thanks
Upvotes: 0
Views: 122
Reputation: 276181
Just use the .on
function. It should compile fine:
$textbox.on('keyup',()=> FuncA(id,max));
Upvotes: 0
Reputation: 1441
How did you ever come up with this? Every time you realize you are writing a code to a string, you know you are doing it wrong. The eval
function and the Function
constructor should be forgotten.
$textbox[0].onkeyup = function () { FuncA(id, max); }; // Solution 1
$textbox[0].onkeyup = FuncA.bind(null, id, max); // Solution 2
// Using jQuery
$($textbox[0]).keyup(FuncA.bind(null, id, max));
Upvotes: 4