rarebit Posted September 24, 2008 Share Posted September 24, 2008 Hi, this works in FF2 and Opera, yet fails in IE: <script type="text/javascript"> function test() { var x = 3; var y = 7; return [x, y]; } var a, b; [a, b] = test(); document.write('a: ' + a + ', b: ' + b + '<br>'); </script> What's the best solution, please? Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/ Share on other sites More sharing options...
web_loone_08 Posted September 25, 2008 Share Posted September 25, 2008 easiest solution: <script type="text/javascript"> var x = 3; var y = 7; document.write('a: ' + x + ', b: ' + y + '<br>'); </script> Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-650083 Share on other sites More sharing options...
rarebit Posted September 25, 2008 Author Share Posted September 25, 2008 where is the function returning an array? so no you loone that isn't a solution! Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-650276 Share on other sites More sharing options...
RichardRotterdam Posted September 25, 2008 Share Posted September 25, 2008 your syntax i am not familiar with . as for your question do you want the function to return an array? if so then this might be the right direction function test() { var x = 3; var y = 7; return new Array(x, y); } just curious what is [a, b] = test(); suppose to do? Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-650330 Share on other sites More sharing options...
rarebit Posted September 25, 2008 Author Share Posted September 25, 2008 function test() { var x = 3; var y = 7; return [x, y]; } var a; a = test(); document.write('a: ' + a[0] + ', b: ' + a[1] + '<br>'); This is what I tried this morning and it gave no errors but the explorer version still isn't working. So i've finally installed comodo and will get my windows online and find something to help debug it. No this example doesn't really do anything, it was just a testbed for the question. There's another variation to use 'pointers' but i've not looked into it with js (just saw a comment and thought i'd give it a quick try). I'll add your part and see if ie bails out. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-650385 Share on other sites More sharing options...
RichardRotterdam Posted September 25, 2008 Share Posted September 25, 2008 you're trying to apply pointers in javascript??? isn't that a C/C++ thing? If so that could be interesting I look forward to seeing a solution to this just for the fun of it Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-650387 Share on other sites More sharing options...
rarebit Posted September 25, 2008 Author Share Posted September 25, 2008 yeah thats why I know it, but there was a comment on a page about arrays and something to do with passing 'array.slice()' as a reference. The quick test I tried didn't work but made a 'mental' note to look into it... Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-650399 Share on other sites More sharing options...
web_loone_08 Posted September 26, 2008 Share Posted September 26, 2008 where is the function returning an array? so no you loone that isn't a solution! there is no array; because you really don't need an array for two variables - plus i eliminated the function - so yes - that is the simplest way to accomplish what you wanted to do. also why don't you just create a normal array (new Array()), add the number/variables to that and use a for loop to document.write() out each key? That makes more sense to me and it is browser compatible that way too. Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651007 Share on other sites More sharing options...
rarebit Posted September 26, 2008 Author Share Posted September 26, 2008 I think you missed the point of a function returning numerous variables, yes I was using the modern interpretation, like many modern languages allow (e.g. FF, Opera). The example was just that, a simple example, so getting rid of the function was inappropriate, too obvious to be true, but I 'pose I did give the bone... Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651434 Share on other sites More sharing options...
web_loone_08 Posted September 27, 2008 Share Posted September 27, 2008 well unfortunately your method did not work in IE and my methods are cross browser; so you will have to choose how you want to do this - cross browser or browser specific only - up to you. also, you really should not use a function with document.write(); that is not the best method to do what your trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651641 Share on other sites More sharing options...
rarebit Posted September 27, 2008 Author Share Posted September 27, 2008 I don't think you comprehend what I was doing, basically because you removed the function entirely, even though the post title inferred the use of a function. Once again this was just a test example and in the real thing it doesn't use 'document.write', but could you explain why it's bad to use it? Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651782 Share on other sites More sharing options...
web_loone_08 Posted September 27, 2008 Share Posted September 27, 2008 Because you should be using DOM at this point and if you were; you probably could get this to work the way you wanted it to, but obviously there is a problem with using document.write() and a function - that is why IE is not letting you do this. You should be using UnObstructive JavaScript Practices and basically you don't comprehend - it's not gonna work the way you have it wrote; at least not cross browser. Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651817 Share on other sites More sharing options...
rarebit Posted September 27, 2008 Author Share Posted September 27, 2008 document.write() has got nothing to do with the real issue, the solution has been sorted, even if using the longer method for ie's sake... it was all about the function returns! ! ! here's the stage 1 demo for the client... retrocentro Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651831 Share on other sites More sharing options...
rarebit Posted September 27, 2008 Author Share Posted September 27, 2008 p.s. using ie6 the anims seem a bit jittery and have an issue which reloads the images (not that i've gone to extent of preloading, even though the ones it loads are definitely already loaded). Also when you solve the puzzle it flashes everything, very strange. This are all ie6 issues. Yes - it starts and resets to a simple solution, so it's quick to test, proper is commented out. Yes - The brown square zindex has some issues at times, to be looked into. Yes - Theres a few more issues, but when I spend time on it i'll sort them... Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651832 Share on other sites More sharing options...
web_loone_08 Posted September 27, 2008 Share Posted September 27, 2008 that's good - glad you got the problem resolved - good luck with the other issues Quote Link to comment https://forums.phpfreaks.com/topic/125697-solved-returning-dynamic-arrays/#findComment-651833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.