javascript - First sums, second doesn't -> why? -


  & lt;! - पहले - & gt; & LT; स्क्रिप्ट & gt; Var कुल = 0; Var newAccumulator = function () {रिटर्न फ़ंक्शन (i) {total + = i; }; } Var foldl = function (arr, putNum) {for (var i = 0; i & lt; arr.length; ++ i) {putNum (arr [i]); }} गुनाह ([1, 2, 3, 4], नया आकस्मिक ()); Document.write ("योग:" + कुल + "& lt; br / & gt;"); & Lt; / स्क्रिप्ट & gt; & Lt;! - सेकंड - & gt; & LT; स्क्रिप्ट & gt; Var कुल = 0; Var newAccumulator = फ़ंक्शन (i) {कुल + = i; } Var foldl = function (arr, putNum) {for (var i = 0; i & lt; arr.length; ++ i) {putNum (arr [i]); }} गुनाह ([1, 2, 3, 4], नया आकस्मिक ()); Document.write ("योग:" + कुल + "& lt; br / & gt;"); & Lt; / स्क्रिप्ट & gt;    

कॉल में foldl आप नया एक्सेमुलेटर फ़ंक्शन:

  गुनाह ([1, 2, 3, 4], नयाएकुम्युलेटर ());  

पहले मामले में यह एक समारोह देता है जो संक्षेप करता है:

  रिटर्न फ़ंक्शन (i) {total + = i; };  

दूसरे मामले में newAccumulator को कॉल कुछ भी वापस नहीं करता है, इसलिए foldl में कोई फ़ंक्शन नहीं है जिसे कॉल कर सकता है राशि की गणना करने के लिए।
आपको नये कोडमांड को सीधे foldl से गुजरना चाहिए, यह मूल्य नहीं है (वापस नहीं):

  foldl ([1, 2] , 3, 4], नया एजूमुलेटर);  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -