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
class EventManager | |
constructor: ()-> | |
@list = {} | |
set: (elmName, event, fnc) -> | |
@list[elmName] = @list[elmName] || {} | |
@list[elmName] = | |
elO:document.getElementById elmName | |
ev:event | |
fn:fnc |
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
//sum(10)(10) → 20 | |
function sum(x, y) { | |
return x + y; | |
} | |
funtion c_sum(x) { | |
return function(y) { return sum(x,y); } | |
} |
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
//引用http://addyosmani.com/resources/essentialjsdesignpatterns/book/ | |
var Singleton = (function(){ | |
var instantiated; | |
function init (){ | |
// singleton here | |
return { | |
publicMethod: function(){ | |
console.log( 'hello world' ); | |
}, | |
publicProperty: 'test' |
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
// htmlがこんな感じだとして | |
// <div id='hoge'>hoge</div> | |
// | |
var addEvent = function(elName, ev, fn) { | |
var el = document.getElementById(elName); | |
if(el.addEventListener) { | |
el.addEventListener(ev, fn, false); | |
} else if(el.attachEvent){ | |
el.attachEvent('on' + ev, fn); | |
} else { |
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
//引用URL:http://addyosmani.com/resources/essentialjsdesignpatterns/book/ | |
var module = (function() { | |
var _private = { | |
i:5, | |
get : function() { | |
console.log( 'current value:' + this.i ); | |
}, | |
set : function(val) { | |
this.i = val; | |
}, |
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
/** | |
* HTMLはこんな感じ | |
* <html> | |
* <head> | |
* <meta charset="UTF-8" /> | |
* <title>クロージャの勉強</title> | |
* <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
* </head> | |
* <body> | |
* <ul class="member"></ul> |
NewerOlder