PDA

View Full Version : Buggy in firebug ???



Stephan123
16 Dec 2009, 1:26 AM
Hello !

I have test an simple script.


Ext.onReady(function(){

// Constructor
var BaseCar = function(config) {
this.octaneRequired = 86;

this.shiftTo = function(gear){
this.gear = gear;
}

this.shiftTo('park');
};

// Prototyp
BaseCar.prototype = {
engine : 'I4',
turbo : false,
wheels : 'basic',
getEngine : function(){
return this.engine;
},
drive: function() {
return "Vrrrrooooooom - I'm driving!";
}
};

var auto2 = Ext.extend(BaseCar,{
turbo: true,
wheels: 'premium',
constructor: function(){
auto2.superclass.constructor.call(this);
this.octaneRequired = 93;
},
drive: function(){
this.shiftTo('drive');
auto2.superclass.drive.call(this);
},
getEngine: function(){
return this.engine + " Turbo";
}
});

var myCar = new auto2();
// console.dir(myCar);

});

When i type in the firebug the command


console.dir(auto2);

I became the message

ReferenceError: myCar is not defined

When i type in the script

console.dir(myCar);
It works. Is that an buggy in the firebug ???

The next question is for my better understanding.

I have my class 'auto2'. When i will work with this class must i make an instance
from this class ???

For example class 'myCar' .

Your sincerly

Stephan

stephen.friedrich
16 Dec 2009, 2:14 AM
mycar and auto2 are defined _inside_ your anonymous function passed to onReady.
They are not visible outside of it, so firebug correctly says its undefined.

BTW: You should name it Auto2 (capital first letter) instead of auto2.
And yes, you need to use new to create an instance.

I recommend to work through a good JS book - unfortunately there are dozens of bad books and only a couple good ones (JavaScript Ninja, JavaScript - the good parts), which are targeted more to the advances JS developers. "JavaScript: The Definive Guide" is decentm though a bit dated and the new JavaScript Programmer's Reference seems nice, too.
ExtJS learning center ishelpfull, too, for example http://www.extjs.com/learn/Manual:Intro

Animal
16 Dec 2009, 2:15 AM
Basic Javascript: Those vars are local to the function they are in.

Stephan123
16 Dec 2009, 3:45 AM
Hello !


Thanks for the information.
There are to many bad books about javascript !!!


Your sincerly

Stephan