From e841ed520e32c68467f1730aa3da46be082b81d1 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Thu, 1 Nov 2012 11:17:06 +0100 Subject: [PATCH] Note about memoizing collections and functions Thanks @puzrin! --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 05d5db5..b99b397 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,10 @@ memoized("12", true); // Cache hit memoized({ toString: function () { return "12"; } }, {}); // Cache hit ``` +__Note. If your arguments are collections (arrays or hashes) that you want to memoize by content (not by self objects), you need to cast them to strings__, for that just use [primitive mode](#primitive-mode). Arrays have standard string representation and work with primitive mode out of a box, for hashes you need to define `toString` method, that will produce unique string descriptions. + +Similarly __if you want to memoize functions by their code representation not by their objects, you should use primitive mode__. + ### Memoizing asynchronous functions With _async_ option we indicate that we memoize asynchronous function.