Skip to content

Instantly share code, notes, and snippets.

@rnapier
Last active August 29, 2015 14:04
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 rnapier/478465d1b15e95b98b42 to your computer and use it in GitHub Desktop.
Save rnapier/478465d1b15e95b98b42 to your computer and use it in GitHub Desktop.
Spooky action at a distance when you don't use self
// Try this in a commandline app vs a playground. The behaviors are different.
class MyClass {
func doSomething() {
refresh() // I wonder which refresh we'll get?
}
}
// Not only does this change the behavior of doSomething()... (see below)
// extension MyClass {
// func refresh() {
// println("I'm an extension refresh")
// }
//}
func refresh() {
println("I'm the global refresh function.")
}
// ... but it behaves *differently* if it's here
//extension MyClass {
// func refresh() {
// println("I'm an extension refresh")
// }
//}
MyClass().doSomething()
// see also https://gist.github.com/rnapier/4213dc64206b17df6935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment