1

I've seen a few JavaScript code examples that use this sort of syntax:

function(foo:String) {
  // code
}

I assume it does some sort of typecasting, but haven't been able to find much information about this syntax. Does anyone know what this is called, and where it is documented? Is this strict JavaScript or a browser extension?

4
  • Can you show us an example source? Commented Oct 25, 2011 at 14:57
  • "I've seen a few JavaScript code examples" Where? Commented Oct 25, 2011 at 14:58
  • It's popped up mostly in dumb little sample bits on LifeHacker. I was googling for TextMate themes and came across screenshots. Could very well be ActionScript as BoltClock suggests, though in the editor "JavaScript" is selected for syntax highlighting. Commented Oct 25, 2011 at 14:59
  • Here's a link: lifehacker.com/5817833/the-best-programming-text-editor-for-mac Commented Oct 25, 2011 at 15:00

1 Answer 1

5

As far as I know, that's not valid JavaScript. Rather, it's ActionScript (with both languages being based on the ECMAScript standard). It simply tells the compiler that the parameter's type is String or any of its subclasses.

This declaration is covered in Adobe's AS3 documentation for variables. The same syntax is used for local variables, fields, function parameters and function return types.

Sign up to request clarification or add additional context in comments.

3 Comments

Ah, thank God! I was beginning to wonder if I had a huge gap in my knowledge of JavaScript!
That would make a LOT of sense. I saw this in this screenshot and assumed it was JavaScript: lifehacker.com/5817833/the-best-programming-text-editor-for-mac
@JamesJohnson, I was similarly terrified.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.