Last active
August 29, 2015 14:00
-
-
Save beratdogan/11237301 to your computer and use it in GitHub Desktop.
[JavaScript][CoffeeScript] Degisken/Fonksiyon Etki Alanlari
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
$('#menu a').click(function(event) | |
{ | |
// $(this) | |
// Bize '#menu a'ya ait tiklanmis olan elementi gosterecektir. | |
$('#menu li').each(function(index) | |
{ | |
// $(this) | |
// Bize '#menu li'ye ait elementleri isaret edecektir. | |
}); | |
}); |
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
$('#menu a').click(function(event) | |
{ | |
$me = $(this); | |
$('#menu li').each(function(index) | |
{ | |
// $(this) | |
// Bize '#menu li'ye ait elementleri isaret edecektir. | |
//$me | |
// Bize '#menu a'ya ait tiklanmis olan elementi gosterecektir. | |
}); | |
}); |
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
Account = (customer, cart) -> | |
@customer = customer | |
@cart = cart | |
$('.shopping_cart').bind 'click', (event) -> | |
# Burada @ bize bind'in icerisindeki 'this'e yonlendirecek, | |
# haliyle asagidaki degiskenler hata verecektir. Cunku | |
# bind'in icerisinde bunlar tanimli degil! | |
@customer.purchase @cart |
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
Account = (customer, cart) -> | |
@customer = customer | |
@cart = cart | |
$('.shopping_cart').bind 'click', (event) => | |
# -> yerine => kullandiktan sonra CoffeeScript artik @ 'i | |
# kullandigimizda bind'e degil, sinifin kendisine atif yapacaktir. | |
# yani artik degiskenlerimiz sinifta tanimli oldguklarindan dolayi | |
# artik erisilebilir durumda olacaktirlar. | |
@customer.purchase @cart | |
# Peki ya burada bind'in kendisine atif yapmak icin ne gerekli? | |
# Uzuuun uzun 'this' yazilmasi gerekli. Biliyorum Coffee'nin | |
# kisa sozdizimine alistiktan sonra buyuk bir zulum bu ancak | |
# mecburiyet... :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment