Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the difference between plug-in-type methods and methods in a global variable
    primarykey
    data
    text
    <p><strong>In terms of efficiency,</strong></p> <p>what's the fastest and most standard way to tweak a function in javascript?</p> <p>Plugin-style coding would be like this.</p> <pre><code>; (function ($, window, document, undefined) { var pluginName = "SoketManager", dataPlugin = "plugin_" + pluginName, settings = { target: this, width: 350, height: 150, theme: 'default' } var Plugin = { // instance... } Plugin.prototype = { connect: function() { //something. }, disconnect: function() { //something. }, sendmessage: function() { //something... }, etc: function() { } //etc2: function() ....... } $.fn[pluginName] = function (arg, contents) { var args, instance; if (typeof arg === 'string' &amp;&amp; typeof instance[arg] === 'function') { args = Array.prototype.slice.call(arguments, 1); return instance[arg].apply(instance, args); } </code></pre> <p>And using global variable would be like this..</p> <pre><code>var SocketManager = { sock: '', connect: function () { var stdInfo = new JSONClientParameters(); var socket = io.connect('http://192.168.1.39:3000', { query: stdInfo.toGetString() //'reconnect': true, // 'reconnection delay': 500,//default 500 //'max reconnection attempts': 10 }); kdbSocketManager.ksock = socket; socket.on('connect', function () { alert('successfully connected to the database!!'); }); }, disconnect: function () { this.ksock.disconnect(); }, sendMessage: function (pMsg, pTargetId) { this.ksock.emit('sendMessage', { msg: pMsg, targetId: pTargetId }); }, </code></pre> <p>I see no point in coding like the plugin-way. Is it much more simple and easy to read to code like the latter one? could somebody explain this in detail? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload