禁止使用类似“eval()”的方法。
setTimeout()、setInterval()、setImmediate()或者execScript()这些函数可以接受一个字符串作为其第一个参数,比如
setTimeout('alert(`Hi!`);', 100);
这种行为被认为是隐式“eval()”,不推荐使用。
function alert(arg: string) {
console.log(arg);
}
const time = 100;
setTimeout(() => {
alert('Hi!');
}, time);
setInterval(() => {
alert('Hi!');
}, time);
const fn = () => {
console.info('fn');
};
setTimeout(fn, time);
class Foo {
public static fn = () => {
console.info('static');
};
public meth() {
console.info('method');
}
}
setTimeout(Foo.fn, time);