Hallo,
wenn ich Crockfords memoizer-Funktion
var memoizer = function (memo, formula) {
var recur = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = formula(recur, n);
memo[n] = result;
}
return result;
};
return recur;
};
var factorial = memoizer([1, 1], function (recur, n) {
return (n * recur(n - 1));
});
var fibonacci = memoizer([0, 1], function (recur, n) {
return (recur(n - 1) + recur(n - 2));
});
(s.a. http://books.google.de/books?id=mOQDYOM8TiYC&pg=PT62&lpg=PT62&dq=function+memoizer+crockford&source=bl&ots=ErqT963EcW&sig=JGV3vJyFj5XyV9h8ShNh8gekU-Q&hl=de&ei=ufTLTYnTI8Pn0QGf25TLBg&sa=X&oi=book_result&ct=result&resnum=2&ved=0CCUQ6AEwAQ#v=onepage&q&f=false bzw. http://www.livestream.com/etsy/video?clipId=pla_1463e546-47ed-4a93-b59a-bd52b236e8b8 bei ca. 45.50) in http://jslint.com/ eingebe, erhalte ich einen Fehler:
"Error:
Problem at line 5 character 30: 'recur' has not been fully defined yet.
result = formula(recur, n);"
Warum?
Gruß
jobo