Note that there are some explanatory texts on larger screens.

plurals
  1. POExt JS events/callbacks, object communication for newb
    primarykey
    data
    text
    <p>I'm a self studying student who is brand new to to both javascript and ExtJs. </p> <p>What I am trying to do is create a main class animal, then have two sub classes inherit properties/methods from animal. Those are cat and dog... then I would like to make multiple objects (multiple cat's and dog's) inherit from the class cat and dog. The multiple objects, cat1, mycat, cat2, dog1, mydog, topdog etc... were supposed to be able to talk and listen to each other.</p> <p>when the cat1, mycat etc talk, it's just alert (stuff), and when that happens the dog alerts "mydog heard that".</p> <p>I did this in javascript already with help from the community (<a href="https://stackoverflow.com/questions/17391549/javascript-callbacks-w-inheritance">How to create listeners with javascript</a>)</p> <p>I want to do this now using ExtJS too. This is what I have so far </p> <pre><code>Ext.define('animal', { extend: 'Ext.util.Observable', constructor: function(config) { this.name = config.name; this.addEvents({'makesound' :true}); this.listeners = config.listeners; //animal.superclass.constructor.call(this, config); this.callParent(arguments); }, makesound: function() { alert(this.sound); this.fireEvent('makesound'); // this is wrong isn't it? // I was thinking that the make sound // would trigger the event makesound } }); //var cat = Ext.create('animal'); //var dog = new animal; //cat.makesound(); //dog.makesound(); Ext.define('cat', { extend: 'animal', name: name, sound: 'meow' }); Ext.define('dog', { extend: 'animal', name: name, sound: 'woof' }); var myCat = new cat({ name: 'myCat'}); var myDog = new dog({ name:'mydog', listeners: { makesound: function() { alert('mydog heard that'); } } }); myCat.makesound(); myDog.fireEvent('makesound'); // </code></pre> <p>What I really want is for mycat to make sound, then mydog automatically hear that makesound (the 'meow') and alert my dog heard that. In extJS though. Any help or advice would be very much appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload