logo
IRC Archive / Freenode / #javascript / 2010 / April / 24 / 3
hypnosis
yuor brain is thin
K1ng\
:(
fatbrain
hehe
thinbrain
:(
K1ng\
ok i think i know why
its not problem with that
but problem is $('#outputList').prepend(prepare(json[i]));
its works but just not showing in IE
DukeDrake
hi
I've seen a website on which my scrollwheel acts horizontally
how can I do that?
r0ny
hi,is it possible to load a function after the page is fully loaded?
temp01
window.onload=func
r0ny
it triggers even when i load the page
temp01
it does not trigger while the page is loading
r0ny
window.onload = function () { alert("It's loaded!") }
this is what i did
and it shown the alert box even before loading all contents in the page
temp01
i have a feeling you did window.onload = myFunction()
r0ny
you mean the exact word *function*
oh man,may be i did hat wrong
lemme try again
temp01
window.onload = myFunction(); will run the function without waiting for onload
window.onload = myFunction; will run the function after the page has loaded
r0ny
temp01: i just tried
window.onload = function () { alert("It's loaded!") }
it just loaded before the page is fully loaded
temp01
what stuff do you have on page?
are you loading things using ajax?
r0ny
yes exactly
an ajax function is called at onload on body
temp01
onload doesn't wait for ajax requests to finish
r0ny
oh i see
thats a very good point
any work around?
actually i need to execute a function after the page us competely loaded
temp01
use the ajax event handlers
xhr.onreadystatechaneg
r0ny
let me google
temp01:
document.onreadystatechange=function1; function function1 () { alert(document.readyState);
}
temp01
xhr.onreadystatechange
use that where you make the xhr request. see some examples.
sjokkis
i've got a function here that expects a mainloop as input. how the heck does that work?
can i just store Mainloop.run("") to a variable?
and send it around?
Servercrash
hi how can i convert a string to title case ?
any built in fucntion to do so ?
hello_warudo
If I have a string x, can I go, for (i, j in enumerate(x)){}
I know python
or I have to go int index = 0; for (i in x){++index; blah}
AdamWeston
Servercrash:I don't think so but it should be pretty heasy if you make o hash of lower and uppers, and then use a regex to replace each initial letter
hello_warudo... are you trying to loop through the characters?
hello_warudo
yes
Are strings are mutable in javascript?
AdamWeston
no they arent mutable
for(i=0; i < x.length;i++){/*do something for each letter x[i]*/}
hello_warudo
In Java they aren't mutable either right?
AdamWeston
no idea
my loop there may need a -1 or +1 in the comparison
i always get confused about that
temp01
don't use x[i] to access individual chars. use x.charAt(i)
AdamWeston
my bad
hello_warudo
I'm making a transliterator
so I'll just copy the string char by char and if it's a char I want changed, copy the changed char
then at the end set the original string as the copy
hello_warudo
appending to a string is O(1) I hope
wait it's O(n) isn't it
because strings aren't mutable....
when you modify an array, does it make a new array?
are arrays mutable?
temp01
yes
hello_warudo
yes mutbale
?
temp01
yes
hello_warudo
phew
I'm trying not to do this in totally ineffecient way
a*
does charAt return a string?
or a "char" like in C
even though it's only length one
temp01
there's no special char type in js
all strings are strings
you could also just try it and see
js> typeof "abc".charAt(0)
gbot2
temp01: "string"
hello_warudo
Uncaught SyntaxError: Unexpected token ILLEGAL
temp01
output/error-messages are useless without the related code
hello_warudo
can I put newlines in the definition of an associative array
like var blah = {a: "blah
, b: "as"};
temp01
it's called an object in js and
<temp01> you could also just try it and see
keep the firebug/safari console and try things out
hello_warudo
hmm
tranlit.js:1 refers to the first or second line?
line 1 is 0 right?
temp01
first line
click it and it will take you to the line number
hello_warudo
oh
i had x = blah
it should be var x = blah
I'm used to python
><
temp01
without var, the variable would become global which is bad
so yes, always use var
hello_warudo
var x=document.getElementsByTagName("html");
nor3
what is "shadowing arguments"? google closure compiler is complaining that i'm shadowing an argument here: JSC_VAR_ARGUMENTS_SHADOWED_ERROR: Shadowing "arguments" is not allowed at line 105 character 37 /// optsR.prototype.post = function (path, arguments, options) {
oh great
arguments is reserved
did not know that.. okay thanks
hello_warudo
temp01 um I click it and it doesn't show the file
I'm using google chrome
temp01
hello_warudo: click resources tab and make sure it's enabled
hello_warudo
I think it didn't load
because of a syntax error
what the hell
oxi
hi
What's good practice for a function of a class that returns a boolean, if you're not sure if the information is available?:
hello_warudo
can I have keys that are non english in an associative array
temp01
yes
oxi
u = new user(); ... u.hasIncommingMessage(); -> bool: true/false
but hasIncommingMessage() might fail, depending on if the information is available in u.
hello_warudo
what the fail
it works when I type in into the debugger
but fails when I load it in chrome
temp01
check the file encoding
hello_warudo
file encoding is unicode
can chrome load unicode extensions
temp01
what's the error?
hello_warudo
Uncaught SyntaxError: Unexpected token ILLEGAL chrome-extension://aoofgmnmedhdekpoaaiffimolkmbdgpf/translit.js:1
temp01
maybe some utf bom thing
hello_warudo
is UTF-8 better
or Unicode
for file type
temp01
whatever works
hello_warudo
ohh
it works now
Unicode doesn't work
UTF-8 dpes
cool
it works
but mangles the page
K1ng\
can someone take a look? live: http://www.mwtradingclub.org/live/ the script: http://www.mwtradingclub.org/live/live.js
'fbpic' is undefined in ie
darksider
can anyone recommend any good JS books?
ones that are good for learning with - start to finish - and ones for reference to functions?
like i have a "Perl For Dummies" book that has a function index in the back with a list of like 1000 useful functions
i know a little JS - enough to get by, and enough that i can learn more quite easily, but i would like to have a great knowledge on it as i am taking up on learning CSS as well... tryiong to learn how to combine into some DHTML
K1ng\
darksider, google is your best friend
r0ny
darksider: dont follow any books
just get some code from interweb
execute it if(errors) fi9x it
darksider
yeah thats always good- but i like the way my book shelf looks
with like 35+ programming books
r0ny
may be a waste of time
darksider
not to mention i stay in the scottish countryside- so the internet goes down on occassion, and goes slow quite regularly
temp01
`eloquent
jsBot
eloquent: Eloquent JavaScript is a comprehensive introductory Web-based book with examples and a built-in interpreter. http://eloquentjavascript.net/index.html
temp01
`rhino book
jsBot
rhino book: The 'Rhino Book' is "Javascript: The Definitive Guide" from O'Reilly. http://oreilly.com/catalog/9780596101992/
darksider
nice. thanks man
K1ng\
hey
can i do 2 return?
return fbname;
return fbpic;
in a function?
temp03
return an array
K1ng\
ah
r0ny
thats cool
an explode it
oxi
hi
how do you guys deal with BO's (Business Objects) in AJAX applications?
sjokkis
hey. when i import a module (like Dbus = imports.dbus), how can i see what properties, functions etc are in that module?
oxi
ofcourse most of the stuff can be done by rpc, ... but it's useful to have some objects in the browser, like a "User" object for example
now you can't rely on new User(), if the data must be fetched from the server, which should be done asynchronously
I wonder if you find this practice good or bad?: rely on a Event: User.on('isLoaded.... function: (user){ s = user.getName(); ....
meaning, that the BO's fields are set asynchronously and you continue the relying logic when the BO's "isLoaded" event occurs
zomg
oxi: what else could you do than that?
oxi
zomg: good question
Wes-
FWIW, you *can* do synchronous XHR
oxi
zomg: I thought there might be a nice remoting framework that does a lot of the plumbing automagically
Wes-
Not that I think it's usually good idea
oxi
Wes: yes, you can, but I also think it's a bad idea
zomg
oxi: well, if your objects would mostly be storing data and used for displaying it, you could pretty much just throw JSON at it
but if they would have some sort of business logic as well then it probably won't be that simple
eg. you'd need to process the JSON into the correct object types
oxi
zomg: right, I was targeting later
zomg: exactly..... and I thought of populating the objects fields in their constructor and have some kind of isready or isloaded event
zomg: later I might refactor that into some kind of factory pattern
however, i'm not so sure how I should handle state changes and syncing to the backend
imho it's not practicably to have some kind of lazy load pattern?
zomg
Well I've worked on some apps which had server-side data that needed to be reflected on the client and dynamically updated both ways
basically it just had this sort of an event thing which would notify the app when data was changed and it would change the objects
oxi
like: user.getName(); -> if(user.Name == undfefined) { ... XHR ... user.setName(xhr.name) ... return user.name}
valio
hi, can you recommend me some tutorial for javascript object model
oxi
that would cause the logic to halt when a field is not arleady cached
zomg: ok, great, thanks for sharing