Created
December 3, 2015 00:09
-
-
Save blendsdk/2eca0c9b5e8fd1cc780c to your computer and use it in GitHub Desktop.
Something like what JQuery does
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
console.clear(); | |
var $ = function(selector) { | |
var list = document.querySelectorAll(selector) | |
var each = function(callback) { | |
return function() { | |
for(var a = 0; a != list.length; a++) { | |
var obj = list[a]; | |
callback.apply(obj,arguments); | |
} | |
return list; | |
} | |
} | |
list.show = each(function(){ | |
this.style.display = ''; | |
}); | |
list.hide = each(function(){ | |
this.style.display = 'none'; | |
}); | |
list.bg = each(function(color){ | |
this.style.backgroundColor = color || 'red'; | |
}) | |
return list; | |
} | |
$('pre').bg('blue').hide().show().bg('yellow'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment