javascript - How to input a function in a function -


मैं इस तरह एक हैक कर सकता हूँ:

  function exec (fn) {setInterval ( fn, 0); } Exec ("newfn ()");  

लेकिन एक क्लीनर की तलाश है।

जैसा कि पहले से उल्लेख किया गया है टिप्पणियों में, फ़ंक्शन को किसी अन्य फ़ंक्शन में पास करने का सबसे अच्छा तरीका यह है कि उसे संदर्भ पास करना, उसके नाम वाला स्ट्रिंग नहीं।

उदाहरण:

< पूर्व> फ़ंक्शन फ़ू () {console.log ('इनुसाइड फू'); } Exec (foo);

फ़ंक्शन के अंदर फ़ंक्शन निष्पादित करने के लिए, आपको फ़ंक्शन संदर्भ के बाद () डाल दिया है:

  function exec Fn) {एफ एन (); }  

लेकिन जब आप बिल्कुल ऐसा कर सकते हैं, मुझे exec (foo) over foo ()


Comments

Popular posts from this blog

uislider - In a MATLAB GUI, how does one implement a continuously varying slider from a GUIDE created .m file? -

c# - Highlight all words containing a letter in a richtextbox -

Editing Python Class in Shell and SQLAlchemy -