문제

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):

function myClass() {
    //blah blah
}

myClass.myMethod = function() {
    //your other function
}

myClass.myMethod();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top