Created
March 12, 2013 10:18
-
-
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.
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
(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