View Full Version : Ext.base.borrow not working as with ExtJs 4.0.7?

17 Jan 2012, 7:07 AM
We have an override for Ext.data.AbstractStore that adds plugin-support for Stores. To minimize needed changes between ExtJS updates I coded it with using borrow which borrows the plugin initialization logic from Ext.AbstractComponent like this:

* Add plugin support for stores.
* This is done by borrowing some methods from Ext.AbstractComponent and modifying the constructor of Ext.data.AbstractStore
//borrow plugin methods from AbstractComponent

//add plugin initialisation code at the end of the constructor of Ext.data.AbstractStore:
var i,len;
if (this.plugins)
console.log("Plugins are:",this.plugins);
this.plugins = [].concat(this.plugins);
for (i = 0, len = this.plugins.length; i < len; i++)
this.plugins[i] = this.initPlugin(this.plugins[i]);

In ExtJs 4.0.7 this was working fine, but with ExtJS 4.1Beta1 this bails out in constructPlugin() where plugin is null. I tried to debug it, but debugging borrowed methods is kinda fun. Perhaps its a scope problem. I noticed that Ext.Base.borrow changed a lot between 4.0.7 and 4.1Beta1. So either this introduced a bug or I'm doing something wrong.
If needed I would be willing to provide a complete testcase.

17 Jan 2012, 8:14 AM
So if you look at the prototype of Ext.data.AbstractStore, are the methods there?

30 Jan 2012, 7:27 AM
Yes, all methods are there. I just tried again with 4.1-Beta2. Should I report a Bug?

2 Jan 2013, 1:26 PM
Yes, this is definitively a bug - and potentially a serious one if your app use borrowing methods. Only the last member will be applied/borrowed:

Ext.define('C1', {
name : 'c1',
f1: function(){
console.info('f1', this.name)
f2: function(){
console.info('f2', this.name)
Ext.define('C2', {
name : 'c2'
}, function() {this.borrow(C1,['f1', 'f2'])})

c1 = new C1();
c2 = new C2()

c2.f1(); // only call f2


Fix : we should have a proper closure in base.borrow, or use Ext.Function.clone as in 4.1 :

if (typeof toBorrow == 'function') {
fn = function(b) {
return function() {b.apply(this, arguments)};


2 Jan 2013, 3:09 PM
Are you saying there is a problem with the 4.2 beta? When I run the example code I see:

f1 c1
f2 c1
f1 c2
f2 c2

2 Jan 2013, 11:50 PM
Thanks for the answer, and oups...

Downloaded what I thought to be the latest version from "ExtJS 4.1 beta 2 is available", first post in "ExtJs 4.2.0" Forum !

Base.borrow looks fine in 4.2.0. Cant believe I tried to fix a 4.1 bug...