Created
August 22, 2013 00:22
-
-
Save richistron/6301880 to your computer and use it in GitHub Desktop.
Usando this con coffeeScript
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
(($)-> | |
class Test | |
constructor:(@error = null)-> | |
log: -> | |
if window.log? and error is not null then console.log @error | |
select: -> | |
$elements = $("div") | |
$elements.on "click" , -> | |
### | |
En este momento @ = this es un elemento de jquery | |
que viene de un each realizado por jQuery | |
### | |
$(@).css "background", "red" | |
# probamos el código | |
test = new Test | |
test.select(); | |
test.error "this es un elemento de jquery" | |
test.log(); | |
)(jQuery) | |
(($)-> | |
class Test | |
constructor:()-> | |
log: (@error = null)-> | |
if window.console? and @error? then console.log @error | |
select: -> | |
$elements = $("div") | |
$elements.on "click" , (e)=> | |
### | |
En este momento @ = this es Test class | |
### | |
@log e | |
$(e.currentTarget).css "background", "red" | |
# probamos el código | |
test = new Test | |
test.select(); | |
)(jQuery) |
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
(function() { | |
(function($) { | |
var Test, test; | |
Test = (function() { | |
function Test(error) { | |
this.error = error != null ? error : null; | |
} | |
Test.prototype.log = function() { | |
if ((window.log != null) && error === !null) { | |
return console.log(this.error); | |
} | |
}; | |
Test.prototype.select = function() { | |
var $elements; | |
$elements = $("div"); | |
return $elements.on("click", function() { | |
/* | |
En este momento @ = this es un elemento de jquery | |
que viene de un each realizado por jQuery | |
*/ return $(this).css("background", "red"); | |
}); | |
}; | |
return Test; | |
})(); | |
test = new Test; | |
test.select(); | |
test.error("this es un elemento de jquery"); | |
return test.log(); | |
})(jQuery); | |
(function($) { | |
var Test, test; | |
Test = (function() { | |
function Test() {} | |
Test.prototype.log = function(error) { | |
this.error = error != null ? error : null; | |
if ((window.console != null) && (this.error != null)) { | |
return console.log(this.error); | |
} | |
}; | |
Test.prototype.select = function() { | |
var $elements, | |
_this = this; | |
$elements = $("div"); | |
return $elements.on("click", function(e) { | |
/* | |
En este momento @ = this es Test class | |
*/ _this.log(e); | |
return $(e.currentTarget).css("background", "red"); | |
}); | |
}; | |
return Test; | |
})(); | |
test = new Test; | |
return test.select(); | |
})(jQuery); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment