[英]Javascript - how to use a variable as a function *and* an object literal
I've seen people use a variable as both an object and a function like so: 我见过人们像这样将变量既用作对象又用作函数:
myClass();
and 和
myClass.myMethod();
How do they do that? 他们是如何做到的?
Functions are objects in Javascript so you can set properties (like other functions or objects on them): 函数是Javascript中的对象,因此您可以设置属性(就像其他函数或对象一样):
function myClass() {
//blah blah
}
myClass.myMethod = function() {
//your other function
}
myClass.myMethod();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.