Skip to content

Instantly share code, notes, and snippets.

@BrechtBonte
Last active August 26, 2015 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrechtBonte/73da4c486dbe6e1d71e1 to your computer and use it in GitHub Desktop.
Save BrechtBonte/73da4c486dbe6e1d71e1 to your computer and use it in GitHub Desktop.
some random js class containing DOM
function Circle()
{
var _circle;
function init()
{
_circle = $('<div class="circle"></div>');
$('body').append(_circle);
}
function getDOM()
{
return _circle;
}
return {
init: init,
getDOM: getDOM
};
}
<script src="/js/circle.js"></script>
<script type="application/javascript">
$(function() {
var circles = [];
for (var i = 0; i < 10; i++) {
var circle = new Circle();
circle.init();
circles.push(circle);
}
$.each(circles, function(i) {
this.getDOM().on('click', function() {
alert('much click: ' + i);
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment