Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Simple Encapsulation Class template
- */
- (function (root) {
- "use strict";
- /**
- * Common object params
- * @type {Object}
- */
- var common = {
- publicMethods: ['getName'],
- className: 'MyPlugin'
- },
- /**
- * Main constructor
- * @return {Object} - this handle
- */
- Protected = function () {
- this.name = 'MyName';
- return this;
- };
- /**
- * Main prototype
- * @type {Object}
- */
- Protected.prototype = {
- getName: function () {
- return this.name;
- }
- };
- /**
- * Encapsulation
- * @return {Object} - this handle
- */
- root[common.className] = function () {
- function construct(constructor, args) {
- function Class() {
- return constructor.apply(this, args);
- }
- Class.prototype = constructor.prototype;
- return new Class();
- }
- var publicly = construct(Protected, arguments),
- i,
- l = common.publicMethods.length;
- for (i = 0; i < l; i += 1) {
- (function () {
- var member = common.publicMethods[i];
- root[common.className].prototype[member] = function () {
- return publicly[member].apply(publicly, arguments);
- };
- }());
- }
- return this;
- };
- }(this));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement