Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

inheritance #26

Open
ghost opened this issue Sep 18, 2013 · 6 comments
Open

inheritance #26

ghost opened this issue Sep 18, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented Sep 18, 2013

when you inherit in js

function Foo(){
    var construct = 'foo';
    alert('foo')
}

function Foo2(){}

Foo2.prototype = new Foo();

then constructor is called and alert is popuped

@ghost
Copy link
Author

ghost commented Sep 18, 2013

I think you must hack it some like this

function Foo(){
    this.property=null;
    this.__constructor(arg){
        this.property=arg;
        return this;
    }
}
function Foo2(){}
Foo2.prototype = new Foo();
var instance = new Foo2().__constructor('foo');

or you must totally redesigned javascript like this https://github.com/Gozala/selfish.

@ghost
Copy link
Author

ghost commented Sep 24, 2013

Im created desing pattern for js oop corespondend to php oop. all its work. all reported bugs is fixed. and is only litle diferent. parent is work corectly. but now its not tested, its only design. can you look and send some Feedback ?
Im was looking long time for all post about jsoop. but no one uses parent with private fields and this simple syntax
https://github.com/tito100/PHP-to-Javascript/blob/jsoop/tools/jsoop/oop.js

its only one more other possibility. make it like this. like jquery. https://github.com/Gozala/selfish .but there is also not suported private fields.

@Danack
Copy link
Owner

Danack commented Sep 26, 2013

I'm using this - http://phrogz.net/JS/classes/OOPinJS.html

I know how to fix the private variables/methods issue (I think) and will do it in a day or two.

@ghost
Copy link
Author

ghost commented Sep 26, 2013

its 10 years old.
remember for bug #27 . you cant do private methods. or maybe you can use self for private methods (self=this;self.foo).
also for bug #35 . you cant define properties in prototype. or you can, but you must only declare it. define in constructor.

@ghost
Copy link
Author

ghost commented Sep 26, 2013

also is not good pattern for api. when you do api, and somebody else use it and wont override some method, then must edit api code.
api:

function Foo(){
    this.foo=function(){}
}

usage:

Foo.foo = function(){} // cant be owerride. you must edit api code

in javascript is routinely overriding api methods
when you do it with prototype, then its possible

function Foo(){}
Foo.prototype.foo=function(){}

usage

var old = Foo.prototype.foo;
Foo.prototype.foo=function(){ // now you can override it
    var foo= "doing some";
    old.call(this);
}

@ghost
Copy link
Author

ghost commented Sep 27, 2013

maybe this can work

var Foo=function(){
    var init=true;
    var STATIC_PRIVATE = 5;
    return function(){
        var privateField;
        var priFunc1,priFunc2;
        this.public=6;

        if (init){init=false;
            Foo.prototype.publicFunc=function(){
                var testPrivate = privateField;
                var testPublicPrivate = privateFunc1.call(this);
            }
        }

        priFunc1 = function(){
            return priFunc2.call(this,4);
        };
        priFunc2 = function(arg){
            return this.public+arg;
        };
    }
}();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant