Question

Basically here's what i have gone through so far:

Extend:

Read here

Basically extends means subclassing,in which all the properties of the parent class can be inherited down into the child class.

Require:

Read here

Loads all classes by the given names and all their direct dependencies.

Am I wrong to think these are similar?

I couldn't find any other differences, can someone explain the difference?

Was it helpful?

Solution

Extends Subclassing means if your creating a class B that Extend the class A, B can be treated like an A, and inherit method and attributes. A's methods and attributes become part of your new class B.

Requires It's just a loading mecanism that assure that some required class are loaded before you can use it. For exemple, if you need to display a message box, you will call :

Ext.Msg.confirm("Confirmation", "Do you want to add " + value  + " to the database ?");

Ext.Msg is not a part of your class, you're basically just telling the system to display a Popup. But if you do that when your app launch, before the class Ext.Msg has been loaded, well it will fail.

To summary :

Extends => when you need to become a class X

Requires => when you need to use a class X

OTHER TIPS

Extends -- The class will extend to one parent class. u can see this in controller or store or model which extends to one parent class

Eg

Ext.define("MyApp.controller.ExtendParent", {
    extend: "Ext.app.Controller",

Requires -- The class which needs the functionality from one or more other classes.

Ext.define("MyApp.controller.ExtendParent", {
    extend: "Ext.app.Controller",
    requires: [
        'Ext.MessageBox',
        'MyApp.store.ParentStore',
        'MyApp.view.ParentView'
    ],
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top