View Full Version : how to extend singleton
kostysh
19 Jul 2012, 4:03 PM
Hi,
Does anybody know way to extend or override singleton class?
if I try to extend, I got error:
Uncaught TypeError: Cannot read property '$inheritableStatics' of undefined
if I try to override:
Uncaught TypeError: Object [object Object] has no method 'override'
joeshke
20 Jul 2012, 1:59 AM
Ext.define('App.controller.MySingleton', {
singleton: true,
requires: [ ],
initFunction:function(){
},
otherFunction: function(text){
console.log(text);
}
});
to call the functions:
App.controller.MySingleton.otherFunction("test");
Maybe it helps.
kostysh
20 Jul 2012, 4:04 AM
You have understood me wrong. I know how to define a singleton, but I don know how to extend already defined singleton class.
I think it is not possible. But, perhaps anyone has ideas how to do this.
estesbubba
23 Jul 2012, 11:51 AM
I have tried this with no luck myself but hoping there is a way.
kostysh
23 Jul 2012, 1:52 PM
It seems, extending of singleton class - is impossible by default.
But I have decided my problem in the following way:
// Define a proto class for my singletone
Ext.define('ProtoClass', {
config: {},
method: Ext.emptyFn
});
// Define a original singleton
Ext.define('OrigSingleton', {
extend: 'ProtoClass',
singleton: true
});
// Extending of proto class
Ext.define('NewProto1', {
extend: 'ProtoClass',
method: function() {
console.log('Bla-bla-bla');
}
});
// Extending of proto class
Ext.define('NewProto2', {
extend: 'ProtoClass',
method: function() {
console.log('Bu-bu-bu');
}
});
// Define a new singleton based on proto class 1
Ext.define('NewSingleton1', {
extend: 'NewProto1',
singleton: true
});
// Define a new singleton based on proto class 2
Ext.define('NewSingleton2', {
extend: 'NewProto2',
singleton: true
});
// We have three singletons based on one proto-class
OrigSingleton;
NewSingleton1;
NewSingleton2;
GustavR
31 Oct 2013, 1:03 AM
Thanks to kostysh I found my solution as well, thought I share it.
How to extend ExtJs singleton class already defined by framework:
Ext.require('Ext.util.History', function() {
Ext.define('My.util.History', {
extend: 'Ext.util.History.self',
singleton: true,
startUp: function() {
// do some own stuff
this.callParent(arguments); // you can even use callParent
}
});
});
Powered by vBulletin® Version 4.2.3 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.