Created
November 30, 2011 16:44
-
-
Save rummelonp/1409749 to your computer and use it in GitHub Desktop.
JavaScript の this による破滅
This file contains hidden or 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() { | |
var Hametsu1; | |
Hametsu1 = (function() { | |
function Hametsu1() { | |
$(function() { | |
return $(document).delegate('a', 'click', this.say); // this が document を指すのであぼーん | |
}); | |
} | |
Hametsu1.prototype.say = function() { | |
return window.alert(this.getName()); | |
}; | |
Hametsu1.prototype.getName = function() { | |
return 'Hametsu1'; | |
}; | |
return Hametsu1; | |
})(); | |
}).call(this); |
This file contains hidden or 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() { | |
var Hametsu2; | |
Hametsu2 = (function() { | |
function Hametsu2() { | |
var self; | |
self = this; // 別の変数に入れる | |
$(function() { | |
return $(document).delegate('a', 'click', self.say); // あぼーんしない | |
}); | |
} | |
Hametsu2.prototype.say = function(e) { | |
return window.alert(this.getName()); // this が a を指すのであぼーん | |
}; | |
Hametsu2.prototype.getName = function() { | |
return 'Hametsu2'; | |
}; | |
return Hametsu2; | |
})(); | |
new Hametsu2; | |
}).call(this); |
This file contains hidden or 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() { | |
var Hametsu3; | |
Hametsu3 = (function() { | |
var self; | |
function Hametsu3() {} | |
self = Hametsu3; // 別の変数に入れる | |
Hametsu3.say = function(e) { | |
return window.alert(self.getName()); // あぼーんしない | |
}; | |
Hametsu3.getName = function() { | |
return 'Hametsu3'; | |
}; | |
$(function() { | |
return $(document).delegate('a', 'click', self.say); // あぼーんしない | |
}); | |
return Hametsu3; | |
})(); | |
new Hametsu3; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment