Namespace Pot.Plugin
Defined in: <pot.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Pot plugin object.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
Pot.Plugin.add(name, (method), (force))
Add plugin function.
|
<static> |
Pot.Plugin.has(name)
Check whether Pot.Plugin has already specific name.
|
<static> |
Pot.Plugin.list()
List the Pot.Plugin function names.
|
<static> |
Pot.Plugin.remove(name)
Removes Pot.Plugin's function.
|
Namespace Detail
Pot.Plugin
Pot plugin object.
// Register my plugin function. Pot.addPlugin('myFunc', function(msg) { alert('myFunc: ' + msg); }); // Call function that is able to refer from the Pot object. Pot.myFunc('Hello!'); // 'myFunc: Hello!' // Check exists. debug( Pot.hasPlugin('myFunc') ); // true // Register other plugin function. Pot.addPlugin('myFunc2', function(a, b) { return a + b; }); // Call other function. debug( Pot.myFunc2(1, 2) ); // 3 // addPlugin does not overwrite function on default. debug( Pot.addPlugin('myFunc', function() {}) ); // false // View list of plugins. debug( Pot.listPlugin() ); // ['myFunc', 'myFunc2'] // Remove my plugin. Pot.removePlugin('myFunc'); debug( Pot.hasPlugin('myFunc') ); // false debug( Pot.listPlugin() ); // ['myFunc2']
Pot.addPlugin({ foo : function() { return 'foo!'; }, bar : function() { return 'bar!'; }, baz : function() { return 'baz!'; } }); debug(Pot.foo() + Pot.bar() + Pot.baz()); // 'foo!bar!baz!'
// Register function. Pot.addPlugin('foo', function() { return 'foo!'; }); // Try change function. var newFoo = function() { return 'NewFoo!' }; debug( Pot.addPlugin('foo', newFoo) ); // false // Overwrite plugin function. debug( Pot.addPlugin('foo', newFoo, true) ); // true debug( Pot.foo() ); // 'NewFoo!'
var toArray = function(string) { return string.split(''); }; // Plugin function has 'deferred' method. Pot.addPlugin('toArray', toArray); // Synchronous debug( Pot.toArray('abc') ); // ['a', 'b', 'c'] // Asynchronous Pot.toArray.deferred('abc').then(function(res) { debug(res); // ['a', 'b', 'c'] });
var string = '\t abc\n \t '; // Original Pot.trim(). debug(Pot.trim(string)); // 'abc' // Overwrite Pot.trim(). Pot.addPlugin('trim', function(s) { return s.replace(/^ +| +$/g, ''); }); // New Pot.trim(). debug(Pot.trim(string)); // '\t abc\n \t' // Removes new Pot.trim(). Pot.removePlugin('trim'); // Back to the original. debug(Pot.trim(string)); // 'abc'
Method Detail
<static>
{Function}
Pot.Plugin.add(name, (method), (force))
Add plugin function.
Pot.addPlugin('foo', function() { alert('foo!') }); Pot.foo(); // 'foo!'
- Parameters:
- {String|Object} name
- A name of Plugin function. or object.
- {Function} (method)
- A plugin function.
- {Boolean} (force)
- Whether overwrite plugin. (default=false).
- Returns:
- {Boolean} Return success or failure.
<static>
{Function}
Pot.Plugin.has(name)
Check whether Pot.Plugin has already specific name.
debug( Pot.hasPlugin('hoge') ); // false Pot.addPlugin('hoge', function() {}); debug( Pot.hasPlugin('hoge') ); // true
- Parameters:
- {String|Array} name
- A name of Plugin function. or Array.
- Returns:
- {Boolean} Returns whether Pot.Plugin has already specific name.
<static>
{Function}
Pot.Plugin.list()
List the Pot.Plugin function names.
Pot.addPlugin('foo', function() { alert('foo!') }); Pot.addPlugin('bar', function() { alert('bar!') }); debug( Pot.listPlugin() ); // ['foo', 'bar']
- Returns:
- {Array} Returns an array of function names.
<static>
{Function}
Pot.Plugin.remove(name)
Removes Pot.Plugin's function.
Pot.addPlugin('hoge', function() {}); debug( Pot.removePlugin('hoge') ); // true Pot.hoge(); // (Error: hoge is undefined)
- Parameters:
- {String|Array} name
- A name of Plugin function. or Array.
- Returns:
- {Boolean} Returns success or failure.