Skip to content

Instantly share code, notes, and snippets.

@honbin
honbin / gist:1992718
Created March 7, 2012 11:57
イベント管理(coffeeスクリプトのお勉強)
class EventManager
constructor: ()->
@list = {}
set: (elmName, event, fnc) ->
@list[elmName] = @list[elmName] || {}
@list[elmName] =
elO:document.getElementById elmName
ev:event
fn:fnc
@honbin
honbin / gist:1939071
Created February 29, 2012 08:09
カリー化のお勉強
//sum(10)(10) → 20
function sum(x, y) {
return x + y;
}
funtion c_sum(x) {
return function(y) { return sum(x,y); }
}
@honbin
honbin / gist:1938826
Created February 29, 2012 07:18
sigletonパターン勉強1
//引用http://addyosmani.com/resources/essentialjsdesignpatterns/book/
var Singleton = (function(){
var instantiated;
function init (){
// singleton here
return {
publicMethod: function(){
console.log( 'hello world' );
},
publicProperty: 'test'
@honbin
honbin / gist:1937994
Created February 29, 2012 05:03
イベントハンドラの共通化
// 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 {
@honbin
honbin / gist:1937694
Created February 29, 2012 04:23
ファサードパターンお勉強1
//引用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;
},
@honbin
honbin / gist:1883443
Created February 22, 2012 08:39
クロージャのサンプル(ulのmemberクラスにli要素を生成して、クリックイベントをはる。jquery利用)
/**
* 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>