question about function Construction

36 views
Skip to first unread message

mue...@gmail.com

unread,
Mar 30, 2013, 5:11:47 PM3/30/13
to kern...@googlegroups.com
function Construction issue

Hi, first of all sorry for my English)
I started using Kernel recently and I want to ask the following question:

I want to create some inheritance, for example I wrote the Function constructor

function Menu(){}

I extended this function and wrote other function

function Extended_Menu(){}

I want to create module from  function Extended_Menu(){}

As far as I understand, It should looks like as
Kernel.module.define("extendMenu", new Extended_Menu() ) ?
Could you please explain, where Menu(){}  and Extended_Menu() should be placed, in this case ?
Should I extend Kernel and stored this functions in some object into Kernel ?
I will be really thankful for any suggestion on this matter.

alindsay55661

unread,
Mar 30, 2013, 5:23:04 PM3/30/13
to kern...@googlegroups.com
Hi, and thanks for the question. Please note that Kernel doesn't use constructor functions for some time now. The main reason I did this was to make extensions and mixins easier. Here is how you can extend modules.

// Note: the second argument is an object literal, not a function 
Kernel.module.define('Menu', { ... });

Kernel.module.define('ExtendedMenu', {
  extend: 'Menu',
  ...
});

So by using the `extend` property you can extend other modules. It will use the module you are extending as the base and then apply your extended definition on top of it. It is even possible to extend multiple modules like this:

Kernel.module.define('SuperExtendedMenu', {
  extend: ['Menu', 'ExtendedMenu']
});

This will apply the module definitions in the order specified: Menu, ExtendedMenu, SuperExtendedMenu.

Let me know if you have any other questions.

Alan

mue...@gmail.com

unread,
Mar 31, 2013, 4:40:10 PM3/31/13
to kern...@googlegroups.com
Yes, I understand. Thank you.
Reply all
Reply to author
Forward
0 new messages