javascript - Module pattern callback implementation -


I am re-writing a simple app using HTML / CSS / JavaScript which can be used for images using intervals Creates animations with, and there is a bunch of buttons that control these animations.

It is scaling and really messing up, with a logic mixed with DOM manipulations via javascript via javascript script file.

So I design module patterns

Based on your app's description, is there a problem with this callback implementation for the module?

Or with module implementation?

In this example, what is the best way to declare private variables and access them through public APIs? Gates and Setters? Are they really necessary? I want to write a readable code but I do not want to do super-architect things.

  (function ($) {$ .module = function (options) {var module = {options: $. (): (Callback: {start: false}}, options), start : Function (callback) {//console.log ('personal start method'); if (callback === "type of function") {callback ();}}} // public API return {start: function () {//console.log('public start method '); Module. Start (module option, callback .start);}}}} ($)); Var myModule = $ Module ({callbacks: {start: function () {console.log ('start callback!')}}}}) MyModule.start ();   

is a sample.

Just because it works for me, and I have seen other implementations, which contain some code that looks like this:

  callback: function (method ) {If (method of type === "function") {var args = []; For (var x = 1; x & lt; = arguments.length; x ++) {if (argument [x]) {args.push (argument [x]); }} Method.apply (this, args); }},   

I'm not sure what to do with this last code. Is it intended to return the data in the callback function when I send the module immediately? If so, how does this work?

Is there a problem in this callback implementation module?

If this does not happen the same.

Or with module implementation?

Your immediate option should probably use one of the assets, writing on the current one complete callback object.

I'm not sure what else it is to get the code I found is to return the data to the callback function

Yes

one ?? | When I have registered the module immediately, does it support many arguments?

No, it is not with registration. It will call method which is passed as a parameter for this callback function.

By using this code you will be free of the need to do this typef check each time you just write to

  helper.callback (This.options.callbacks.start == "function") this.options.callbacks.start (/ * Arguments * /) instead of (this.options.callbacks.start, / * Optional Arguments / /)   

However, unless you feel that you do not need this assistant, you will not need this assistant.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -