Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Created March 12, 2013 10:18
Show Gist options
  • Save mertenvg/5141788 to your computer and use it in GitHub Desktop.
Save mertenvg/5141788 to your computer and use it in GitHub Desktop.
Create node/module objects and be able to treat them as dom insertable nodes. Requires jQuery. Combined with jqPersist the object can be persisted with the node and linked up again later to maintain instance values etc.
(function ($) {
var myP = function (arg) {
this.init('<p />');
if (typeof $.fn.persist$ === 'function') {
this.persist$();
}
this.text(arg);
this.test = function () {
console.log(this.text());
};
};
myP.prototype = $();
$(function () {
var $body = $('body');
$body.append(new myP('one'));
$body.append(new myP('two'));
$body.children('p').each(function () {
if (typeof $.fn.get$ !== 'function') {
return;
}
$(this).get$().test();
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment