Created
January 8, 2014 00:40
-
-
Save radicaled/8309609 to your computer and use it in GitHub Desktop.
Dart's lazy initialization in action.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var potatoSack = []; | |
var potato = buildPotato(); | |
String buildPotato() { | |
var tater = 'a delicious potato'; | |
potatoSack.add(tater); | |
return tater; | |
} | |
void main() { | |
print(potatoSack); //output is [] (empty array) | |
print(potato); // now calls buildPotato(); | |
print(potatoSack); // output is ['a delicious potato'] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment