prototype - Why doesn't my JavaScript constructor pattern work? -
why doesn't javascript pattern work? example try call function this.prepare.build()
, doesn't works. gives me error:
this.prepare.build not function
<script> $(function () { new $.myfunction(); }); </script> <script> (function($) { 'use strict'; function myfunction(options) { return new myfunction.prototype.init(options); } myfunction.fn = $.myfunction.prototype = { init: function() { console.log('call: myfunction.init') this.prepare.build(); }, prepare: function() { return { build: function() { console.log('call: myfunction.prepare.build'); }, run: function() { console.log('call: myfunction.prepare.run'); } } } } inviter.prototype.init.prototype = inviter.prototype; })(jquery); </script>
might answer question. prepare function build, need call both:
this.prepare().build()
Comments
Post a Comment