I think your issue is that JavaScript does not support function  
overloading.

What your code is equivalent to is:

a = function(p1) {...};
a = function(p1, p2) {...};

The second definition replaces the value of a.

You may want to use the arguments array instead:

function a(p1)
{
        if (arguments.length == 1)
                globalVariable = '1 param called';
        else if (arguments.length == 2)
                globalVariable = '2 param called';

        //or if you want to be fancy:
        globalVariable = arguments.length + ' param called';
}

Alex

On May 7, 2009, at 7:48 AM, slicker wrote:

>
> Hi, I'm trying to embed v8 to my app and have encounter function
> overloading problem
>
> it goes like an example below
>
> ---------------------script-----------------------------
> function a(p1) {
>     globalVariable='1 param called';   //print globalVariable's
> setter value
> }
> function a(p1,p2) {
>     globalVariable='2 param called';
> }
>
> a('1');
> a('1','2');
> ---------------------------------------------------------
> ------------------------result------------------------
> globalVariable='2 param called'
> globalVariable='2 param called'
> --------------------------------------------------------
>
>
> when i run the above script, as u can see 'function a(p1,p2)' is
> always called
>
> That is, function overloading seems doesn't work but it works as
> function 'overwrite'(it always call the latter one with some tests)
>
> I'm wondering I am doing anything wrong because it works properly at
> Chrome but not my embedding application.
>
> Any comments would be helpful and thanked
>
> >

Alex Iskander, TPSi






--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to