dnaof
kindof(), .can., dnaof() - inheritance made easy
Ever struggled with prototype inheritance? Ever wandered why examples of inheritance do not show inheritance deeper than one level? Want it quick, easy and painless?
kindof()
-- creates a new kind (you might want to call it a class or a type)
.can.
-- assign a new ability to a kind (method, function)
dnaof()
-- call the ancestor method (aka the inherited or super)
======
EXAMPLE
Demonstrate creation of kinds, creating and calling both overloaded and not overloaded methods.
OUTPUT
bob can chatalice can chat, alice can talkcandy can chat, candy can talk, candy can discussbzzzz.z.z.z... (alice)bzzzz.z.z.z... (bob)bzzzz.z.z.z... (candy)
CODE
// create a kind of idiot without ancestor: var idiot = // tell what it can do: idiotcan { return thisname + ' can chat' }idiotcan { console } // a new kind of smart inherits from a kind of idiot var smart = // he can also say something: smartcan { // he can say something new, and he can say the same thing as an idiot can: return + ' and talk'} // a kind of a genious can do the same things as an idiot and smart can, and even more: var genious = geniouscan { thisname = name }geniouscan { return + ' and even discuss'} // you must use .create(), not "new" var alice = idiotvar betty = smartvar carol = genious alicename = 'Alice'bettyname = 'Betty' // let them talk: consoleconsoleconsole // let them take some rest: alice betty carol