Jump to content

[SOLVED] returning dynamic arrays


rarebit

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.