Skip to content

Instantly share code, notes, and snippets.

@radicaled
Created January 8, 2014 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radicaled/8309609 to your computer and use it in GitHub Desktop.
Save radicaled/8309609 to your computer and use it in GitHub Desktop.
Dart's lazy initialization in action.
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