JavaScript, the unnecessary part : About Label

For whatever reasons, people might add inline JavaScript to an HTML element

	
<a href="javascript:someFunction();">some link</a>

It works fine since a JavaScript protocol is used here to trigger the function someFunction()

While some people don't like the JavaScript protocol approach, and some other folks adopt the alternative approach like this :

	
<a href="#" onclick="javascript:someFunction();return false;">some link</a>

It stills works, and people may stop figuring out why they "need to" put javascript: inside this onclick attribute before the JavaScript function.

In fact, you can put many things before the inline function.

So this will work.

	
<a href="#" onclick="woofooscript:someFunction();return false;">some link</a>

So this will work,too.

	
<a href="#" onclick="Hello_World_Script:someFunction();return false;">some link</a>

In fact, the word woofooscript or Hello_World_Script are Javascript Label, they're not protocol names.

In JavaScript, we can use a label to help to manage the process flows, in this example, the label myLabel identifies a while loop.

We can put label before almost any kinds of statement, such as an IF statement.

Or a simple block statement

If the statement is an one line statement, we may ignore the curly Braces

That's why it's legal to add javascript: before the javascript function

	
<a href="#" onclick="javascript:someFunction();return false;">some link</a>

It seems interesting to me that using label as a notation of objects instead of using it as a tool to manage flows.

In this case, the label secretInformation is used to group a bunch of private members.

Or place labels before anonymous objects

If we can have a function which is able to access the object linked to a given label name, that would be interesting.

I guess that's it. Hope my little documentation about label would help.

Hedger Wang