View Full Version : [noob need help] onReady with functions trouble
AlienK
29 Sep 2009, 11:21 PM
Hello!
I'm very beginner at ExtJS. I've started with 3.0 version, and now have some problem:
my code is like this:
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../../resources/images/default/s.gif';
function message() {
Ext.Msg.show({
title: 'msg',
msg: 'hey!',
buttons: Ext.Msg.YESNOCANCEL
});
}
Ext.onReady(message());
</script>
and have such error in firebug:
ct is null:
anonymous(Object name=ct, Object name=position)ext-all-debug.js (line 14639)
anonymous(Object name=ct, Object name=position)ext-all-debug.js (line 16425)
anonymous(Object name=ct, Object name=position)ext-all-debug.js (line 21711)
anonymous(Object name=ct, Object name=position)ext-all-debug.js (line 36156)
anonymous(Object name=container, Object name=position)ext-all-debug.js (line 14449)
anonymous()ext-all-debug.js (line 17390)
anonymous("msg")ext-all-debug.js (line 37151)
anonymous(Object title=msg msg=hey! buttons=Object)ext-all-debug.js (line 37336)
message()test.html (line 30)
test.html()test.html (line 34)
ct.dom.insertBefore(this.el.dom, position);\n
What did I do wrong? Help me, please!
-WBR,
Alexey
Animal
29 Sep 2009, 11:29 PM
So what does the call
message()
return to be passed into onReady to use used as a function?
AlienK
29 Sep 2009, 11:50 PM
As I understand, I should pass a function to onReady, and trying pass "message" function to it.
example with inline function:
Ext.onReady(function(){
Ext.Msg.alert('hello', 'hello');
});
works fine, but I'm trying use not inline function "message" and have problem.
Animal
30 Sep 2009, 1:07 AM
You have to read your code. Imagine you are the javascript runtime.
I was taught this about 30 years ago. It's called dry running.
For "Ext.onReady(message());", the dry run goes like this.
First, execute the message() call, then, using the result from that as the first parameter, execute the onReady call.
"message" is a function.
AlienK
30 Sep 2009, 1:38 AM
Oh, how stupid I am)))
I see, thank you.
macpaulos
9 Mar 2010, 7:19 AM
Such a simple idea but ti does work out. I'm trying to follow a tutorial at the moment and it's really confusing me. Dry run it is.
gwalterg
11 Mar 2010, 10:42 AM
Friends, i have the same trouble ( i'm really newbie in extjs and javascript) and can't solve it.
The explanation:
"For "Ext.onReady(message());", the dry run goes like this.
First, execute the message() call, then, using the result from that as the first parameter, execute the onReady call.
"message" is a function. "
is not clear to me. It means that is there to use a return at the end of the function? Means that Ext.onReady(message()); is not correct? What is the right way to use a not anonymous function at the Ext.onReady? Inside a void()?(i try it and didn't work)
I try the example copied exactly from the book Learning Extjs, this is the problematic code:
Function stapler(){
Ext.Msg.show(
{
title: 'Gabriel',
msg: '¿Viste mi engrapadora?',
buttons:
{
yes: true,
no: true,
cancel: true
}
});
}
Ext.onReady(stapler());
And get the same error that generates this tread.
Thanks in advance!
Gabriel
Animal
11 Mar 2010, 11:12 AM
It calls stapler(), and then passes the result (which is NOTHING) to the Ext.onReady function.
It's a very old typo in the book! New editions don't have it.
gwalterg
11 Mar 2010, 11:54 AM
Thanks Animal!
what should be the right way to use a not anonymus function in that case? Can't be done?
babsjr77
11 Mar 2010, 1:34 PM
Ext.onReady(stapler);
You pass a reference to the stapler function to onReady, not the result of stapler().
Mike Robinson
11 Mar 2010, 2:13 PM
One of the unfortunate downsides of JavaScript is that it has essentially no compile-time checking. It's "shades of BASIC, Batman!" (No, not Visual Basic ... that BASIC!)
Anything goes. If it meets the (very liberal) syntax requirements of the language, it gets accepted without so much as a "peep" and it is up to you to find The Bug. Sometimes it really pays to put a cap on your head before coming into work, so you demolish a defenseless piece of cotton cloth instead of your precious hair follicles. (:|
gwalterg
12 Mar 2010, 3:35 AM
Ext.onReady(stapler);
You pass a reference to the stapler function to onReady, not the result of stapler().
babsjr77 (http://www.extjs.com/forum/member.php?u=20141), you save my sanity! Of all solutions that I thought that one was the more simple, and unexpected.
Thanks a lot!
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.