Created
July 17, 2011 01:57
-
-
Save francescoagati/1087021 to your computer and use it in GitHub Desktop.
jquery declarative named scope
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
$.fn.declare.add | |
'set.color': (color) -> @css({'color':color}) | |
'set.bgcolor': (color) -> @css({'background-color':color}) | |
$("div").declare('set.color','green').declare('set.bgcolor','red') |
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
# | |
# an example of named scope like in activerecord | |
# implemented for jquery | |
# | |
# | |
do -> | |
scopes_cache={} | |
fn= (scope,args...) -> scopes_cache[scope].apply(this,args) | |
fn.add= (scopes) -> scopes_cache[scope]=fn for scope,fn of scopes | |
fn.remove= (scope) -> delete scopes_cache[scope] | |
jQuery.fn.declare=fn | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment