Functions in JavaScript are assignable closures, so it is easy to write a lazy initializing function without any if statements.
var getImage = function(name) { var images = { }; var files = MESSAGES_FOLDER.getFiles(); while(files.hasNext()) { var file = files.next(); images[file.getName()] = file.getDownloadUrl(); } return (getImage = function(name) { return images[name]; })(name); }
After the initialization part of the function (making a map of file names to download urls) it is replaced by a new function that does not include the initialization, and that new function is called to get the result for the first use.
This is also an implementation of the State pattern.
Lazy method, it's funny sounds. But about script, yes, its good. I was searched this information, thank you. Yesterday I found article about split method java https://explainjava.com/split-string-java/, pretty good describing this method. Im sure it will help you some day.
ReplyDeletegood method
ReplyDeletewww.apponix.com