Skip to content

Instantly share code, notes, and snippets.

@wende
Created May 28, 2015 12:32
Show Gist options
  • Save wende/e8cb6947dd4979e7a517 to your computer and use it in GitHub Desktop.
Save wende/e8cb6947dd4979e7a517 to your computer and use it in GitHub Desktop.
// Tu standard
function Person(name, age){
this.name = name
this.age = age
}
// Literał jest szybszy niż new Array() i lepiej wygląda
var family = [
new Person("alice", 40)
new Person("bob", 40)
new Person("michele", 40)
new Person("timmy", 40)
]
// zmienna tymczasowa dla perfomancu
var l = family.length
// lepiej dać vara dla bezpieczeństwa niż niszczyć scope
for(var i = 0; i < l; i++) console.log(family[i].name)
// a jeszcze lepiej funkcyjnie
family.map( function(a){ console.log(a.name) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment