var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .
var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .var Class_privateMethod = function (_this_privateVar) { alert(_this_privateVar); return null ; } var Class_publicMethod = function (_this_privateVar) { return Class_privateMethod.call( this , _this_privateVar); } var Class = function () { var privateVar = 'Hello, world!' ; this .publicMethod = function () { return Class_publicMethod.call( this , privateVar); } } * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- var ObjectServer = function ()
 - {
 - var objects = new Array (), CURRENT_ID = 1;
 - var result = function (_id)
 - {
 - if (! (_ id instanceof Number))
 - {
 - return ;
 - }
 - if (objects [_id] .external! = _id)
 - {
 - return ;
 - }
 - return objects [_id];
 - }
 - result.create = function (_class)
 - {
 - var object = new _class ();
 - object .external = new Number (CURRENT_ID);
 - for ( var key in _class.external)
 - {
 - object .external [key] = _class.external [key];
 - }
 - objects [CURRENT_ID ++] = object ;
 - return object .external;
 - }
 - result.destroy = function (_id)
 - {
 - if (! (_ id instanceof Number))
 - {
 - return ;
 - }
 - if (objects [_id] .external! = _id)
 - {
 - return ;
 - }
 - delete objects [_id];
 - }
 - return result;
 - }
 - var objs = ObjectServer ();
 
objs(myObject).privateMember;* This source code was highlighted with Source Code Highlighter .
- var global = this ;
 - ( function () {
 - var objs = ObjectServer (); // The ObjectServer function is defined somewhere outside.
 - var Class = function ()
 - {
 - this .privateVar = 'I \' ma private variable. ' ;
 - }
 - Class.prototype.privateMethod = function ()
 - {
 - alert ( this .privateVar);
 - alert ( this .external.publicPrimitiveVar);
 - this .external.publicCompoundVar.push ( this .privateVarDefinedInConstructor);
 - alert ( this .external.publicCompoundVar);
 - }
 - Class.external = new Object ();
 - Class.external.publicPrimitiveVar = 10;
 - Class.external.publicMethod = function ()
 - {
 - objs ( this ). privateMethod ();
 - objs ( this ). privateVar = 'Changed!' ;
 - objs ( this ). privateMethod ();
 - }
 - global.Class = function (_arg)
 - {
 - var result = objs.create (Class);
 - result.publicCompoundVar = new Array ( 'a' , 'b' , 'c' );
 - objs (result). privateVarDefinedInConstructor = _arg;
 - return result;
 - }
 - }) ();
 - var object1 = Class ( 'd' );
 - var object2 = Class ( 'e' );
 - object2.publicPrimitiveVar = 50;
 - object1.publicMethod ();
 - object2.publicMethod ();
 - alert (object1.privateMethod);
 - object2 = new Number (object2 * 1);
 - object2.publicMethod ();
 
* This source code was highlighted with Source Code Highlighter .
- ObjectServer.create = function (_class)
 - {
 - var constructor = new Function ();
 - constructor.prototype = _class.prototype;
 - var object = new constructor ();
 - object .constructor = _class;
 - object .external = new Number ( this .CURRENT_ID);
 - for ( var key in _class.external)
 - {
 - object .external [key] = _class.external [key];
 - }
 - this .objects [ this .CURRENT_ID ++] = object ;
 - _class.apply ( object , Array.prototype.slice.call (arguments, 1));
 - return object .external;
 - }
 
Source: https://habr.com/ru/post/77012/
All Articles