javascript - Creating a editor -
i'm trying understand object inheritance in js exercise, create online editor, 1 i'm writing on.
but.. i'm little confuse here, want use data-* manipulate editor:
<div class="editor__wrapper"> <div data-editor="toolbar"> </div> <textarea data-editor="textarea"></textarea> </div>
so, trying initialize this:
$(window).on('load', function() { $('[data-editor]').each(function() { var element = $(this); var editor = new editor(element); }); });
and editor:
var editor = function(element) { this.element = element; };
but not want here..
i want initialize data-* create toolbar if toolbar , create editor if editor, make 2 inherit father commum properties.
i'm little lost here, guys think this? there better way???
thanks.
if trying setup editor handle create depending on value, can perform following:
<script type="text/javascript"> $(window).on('load', function() { $('[data-editor]').each(function() { var element = $(this); var editor = new editor(element); }); }); var editor = function(element) { this.element = element; switch(element.data("editor")){ case "toolbar": // magic console.log("toolbar"); break; case "editor": // less magic console.log("editor"); break; default: // sad , lonely console.log("lonely"); break; } }; </script>
this doesn't object inheritance in js though. need prototyping , gets ... complicated. can see examples here: https://developer.mozilla.org/en-us/docs/web/javascript/introduction_to_object-oriented_javascript#inheritance
Comments
Post a Comment