0

I have a base object class called coretype e.g.

 function coreotype(a,b,c){
    var coreA= a;
    var coreB= b;
    var coreC= c;
    function coreF(){...do something...}
    }

I then have a number of modification processes e.g.

function modifyA(m1){var md1 = m1; function mf(){...do something...}}

and

function modifyA(m1){var md1 = m1; function mf(){...do something...}}

I want to create super object classes of the core type and the 1 of the modification processes to create new object classes e.g. typeA which is an object class of coref + modifyA

so that I can define an object by doing something like:

var thing1 = new typeA(a,b,c,m1)

Is this possible? Also can these super classes be made using an interface so that I could remove say coreB from the resulting super class or am I just expecting more OOP than javascript can deliver? I would prefer an answer using javascript over jquery as I would really like to understand how it is being done. Thanks

2
  • not really a javascript guru, but you might want sometyhing like this modifyA.prototype = new coreotype; modifyB.prototype = new coreotype;.. Commented Jul 23, 2013 at 12:36
  • Thanks I got it working using your suggestion function coreotype(a,b,c){ this.coreA= a; this.coreB= b; this.coreC= c; function coreF(){} } function modifyA(m1){this.md1 = m1; function mf(){}} function modifyB(m1){var md1 = m1; function mf(){}} var typeA = modifyA var typeB = modifyB typeA.prototype = new coreotype(1,2,3); typeB.prototype = new coreotype(1,2,3); var thing1 = new typeA(1); var thing2 = new typeB(2); alert(thing1.coreB + thing2.coreC); Commented Jul 23, 2013 at 21:49

2 Answers 2

1

check it out a post by John Resig about more robust Javascript Inheritance and OOP than the simple prototype: http://ejohn.org/blog/simple-javascript-inheritance/

Sign up to request clarification or add additional context in comments.

Comments

0

Since you really want to understand how this is done.. you must visit -

http://prototypejs.org/learn/class-inheritance

You are free to peek into prototypejs code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.