Methods of my function... How? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Methods of my function... How?

I have a function. And I most create method of this function. But this function don't have a name. function getSomeThink() { // code return function () { // code } } var working = getSomeThink(); working.go(); How to create method 'go' of 'working'? Thank.

8th May 2018, 6:31 PM
k-17
k-17 - avatar
2 ответов
+ 8
or if following your existing code function getSomeThink() { // code return function () { // code alert(42); } } var working= getSomeThink(); working(); the last line will call the function which returned from getSomeThink() but this way you cannot call it "go"
8th May 2018, 6:41 PM
Burey
Burey - avatar
+ 7
follow this pattern function foo(){ this.goo = function(){ alert(42); } } var f = new foo(); f.goo();
8th May 2018, 6:38 PM
Burey
Burey - avatar