[Javascript] Function declaration

Hakan M. hakan at backbase.com
Tue Jan 20 07:12:32 CST 2004


A search on prefixing a function with [variable/indentifier]:: returned 
absolutely nothing for me, but Matt's assumption seem right.

Try this (pseudo)code to see if it works:
//---------------------
var oDiv = document.createElement('div');
oDiv.innerHTML = 'try clicking me';
function oDiv::onmousedown() {
	alert('mousedown!');
}
document.body.appendChild(oDiv);
//---------------------

My guess is:

function oDiv*::onmousedown**
*) oDiv is the object where you want to add a method/define a method
**) The method you wish to add/modify

But again I have to agree with Matt, I have never ever seen this syntax 
in JavaScript before (I've been developing complex javascript 
applications for the last couple of years) but as soon as someone find 
time to check the ECMAScript specs they will probably prove me wrong and 
give me a cone hat to wear in the n00b-corner.

In conclusion I'd like to say, on a personal note, that if the code is 
actually doing the exact same thing as in the example Matt provided, I 
see no reason to use yet another confusing way of doing this. But I 
guess it all comes down to preferred coding practice. :)

Regards,
Hakan

Matt Barton wrote:
> Hi,
> 
> I've never seen that used before in Javascript, but have done in PHP (and I
> would expect the same syntax would be used in similar languages), but only
> for calling a function, never for declaring a function.
> 
> If I had to hazard a guess I'd say that the example you've supplied was
> attemping to define the oncontextmenu function of the TreeView1 object.
> 
> I suppose it would be similar to having:
> 
> <div id="TreeView1"> Yada, yada, yada </div>
> <script language="javascript">
> function customContextMenu () {
>         // do some stuff here
> }
> TreeView1.oncontextmenu = customContextMenu;
> </script>
> 
> I've no idea if that is actually what the code you've supplied is doing, and
> all of the above is untested - I'm just thinking on my feet.
> 
> HTH
> 
> Matt
> 
> ----- Original Message ----- 
> From: "Paul Cowan" <dagda1 at hotmail.com>
> To: <javascript at LaTech.edu>
> Sent: Tuesday, January 20, 2004 12:02 PM
> Subject: [Javascript] Function declaration
> 
> 
> 
>>Hi all,
>>
>>Could anyone explain this function to me:
>>
>>
>>function TreeView1::oncontextmenu(){
>>    //implementation
>>}
>>
>>It is the TreeView1:: before the function name that is something that I
> 
> have
> 
>>never seen before.
>>
>>Thanks
>>
>>Paul
>>
>>_________________________________________________________________
>>Express yourself with cool emoticons - download MSN Messenger today!
>>http://www.msn.co.uk/messenger
>>
>>_______________________________________________
>>Javascript mailing list
>>Javascript at LaTech.edu
>>https://lists.LaTech.edu/mailman/listinfo/javascript
>>
>>--
>>This email has been verified as Virus free
>>Virus Protection and more available at http://www.plus.net
> 
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 
> .
> 




More information about the Javascript mailing list