Custom declare widget

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom declare widget

klng@intersoln.com
Hi,

Could someone please help me on the matter below? Thanks in advance for
the help.

I’ve created two js files as per below. And from another js file I’ve
invoked Singleton.createFruit() but I kept getting  error indicating
Singleton.paint(“Red”) in Apple.js is not a function.

Am I doing something wrong here? Can someone please help advise what is
the right code for trying to achieve what I am trying to achieve?

Thanks

Best Regards


Packages/Singleton.js

define([
   "Packages/Child/Apple"
], function (Apple)
{
    var fruit = {};
   return {
     createFruit: function()
     {
       var h = new Apple ();
     },
     paint: function(color)
     {
       this.fruit.color = color;
     }
});

Packages/Child/Apple.js
define([
   "dojo/_base/declare",
   "Packages/Singleton"],
function (declare, Singleton)
{
   return declare("Packages.Child.Apple", null,
   {
     postCreate: function ()
     {
       var domNode = this.domNode;
       this.inherited(arguments);
       Singleton.paint(“Red”);
     }
   });
});


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Custom declare widget

Jared Jurkiewicz
It  it's probably because you have a circular dependency between those two modules.

On Mar 22, 2017 10:01 AM, <[hidden email]> wrote:
Hi,

Could someone please help me on the matter below? Thanks in advance for
the help.

I’ve created two js files as per below. And from another js file I’ve
invoked Singleton.createFruit() but I kept getting  error indicating
Singleton.paint(“Red”) in Apple.js is not a function.

Am I doing something wrong here? Can someone please help advise what is
the right code for trying to achieve what I am trying to achieve?

Thanks

Best Regards


Packages/Singleton.js

define([
   "Packages/Child/Apple"
], function (Apple)
{
    var fruit = {};
   return {
     createFruit: function()
     {
       var h = new Apple ();
     },
     paint: function(color)
     {
       this.fruit.color = color;
     }
});

Packages/Child/Apple.js
define([
   "dojo/_base/declare",
   "Packages/Singleton"],
function (declare, Singleton)
{
   return declare("Packages.Child.Apple", null,
   {
     postCreate: function ()
     {
       var domNode = this.domNode;
       this.inherited(arguments);
       Singleton.paint(“Red”);
     }
   });
});


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest