Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 7cefb50

Browse files
committed
Merge pull request #5 from nblum/master
Added inheritance example to documentation
2 parents 7bdefad + b37fea9 commit 7cefb50

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ which is designed for easy-to-use implementation purpose in "oldschool" multipag
2020
1. [Mounting plugins](#mounting-plugins)
2121
1. [Configuring plugins](#configure-plugins)
2222
1. [Global messages](#global-messages)
23+
1. [Extending a Plugin (inheritance)](#extending-a-plugin-inheritance)
2324
1. [Dynamic (un)mounting](#dynamic-unmounting)
2425
1. [Best practices](#best-practices)
2526
1. [Building your project](#building-your-project)
@@ -264,6 +265,45 @@ define(['Plugin', 'Window'], function (Plugin, Window) {
264265

265266
All the listeners which have been registered using bindSystemMessage will be destroyed automatically when the plugin instance is destroyed (unmounted).
266267

268+
### Extending a Plugin (inheritance)
269+
270+
Extending a plugin is still simple. Every plugin in the example extends the base plugin "Plugin".
271+
To extend our own plugin we use an Alerter again as example:
272+
273+
``` javascript
274+
define(['Plugin', 'Window'], function (Plugin, Window) {
275+
var Alerter = Plugin.extend({
276+
execute: function () {
277+
var me = this;
278+
me.showMsg(me.$element.text());
279+
},
280+
showMsg: function (msg) {
281+
var me = this;
282+
Window.alert(msg);
283+
}
284+
});
285+
return Alerter;
286+
});
287+
```
288+
289+
Now we implement a SpecialAlerter:
290+
291+
``` javascript
292+
define(['plugins/Alerter'], function (Alerter) {
293+
var SpecialAlerter = Alerter.extend({
294+
showMsg: function (msg) {
295+
var me = this;
296+
//calling base method
297+
me.base('Special:' + msg);
298+
}
299+
});
300+
return SpecialAlerter;
301+
});
302+
```
303+
We overwrite the showMsg function to prepend th 'Special' string to the message.
304+
After that we calling the function from the base class.
305+
306+
267307
### Dynamic (un)mounting
268308
mntyjs uses a Mutation-Observer Shim, which allows you to dynamically add and remove elements which use plugins as well. The MutationObserver will notify mntyjs which will initialize / destroy all the plugins of the according elements.
269309

0 commit comments

Comments
 (0)