<p onclick="fun()"></p>
It seems that event functions can only be written in the global scope. What if I want to call methods in the class?
class xxx(){ func(){}//如果要调用这个方法呢?不能直接写在onclick后面吧 }
温故而知新,可以为师矣。 博客:www.ouyangke.com
If you want to call a function in a class, you have to instantiate it
let x = new xxx()
<p onclick="x.fun()"></p>
First of all, you have to understand that class is just syntactic sugar for the constructor, which is equivalent to
var xxx = (function () { function xxx() {} xxx.prototype.func = function () { }; return xxx; }());
Uh, what does that () after class mean? New syntax?
()
If you want to call a function in a class, you have to instantiate it
First of all, you have to understand that class is just syntactic sugar for the constructor, which is equivalent to
Uh, what does that
()
after class mean? New syntax?