Skip to content

Instantly share code, notes, and snippets.

@richistron
Created August 22, 2013 00:22
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 richistron/6301880 to your computer and use it in GitHub Desktop.
Save richistron/6301880 to your computer and use it in GitHub Desktop.
Usando this con coffeeScript
(($)->
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)
(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