سؤال

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