Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  64] [ 6]  / answers: 1 / hits: 23250  / 12 Years ago, tue, march 20, 2012, 12:00:00

I am a newbie with JavaScript and I feel the unresistible need to strong type my functions parameters for a couple of tools I am coding:




  1. That would give me autocompletion within those functions

  2. Debugging/function access gets more consistent



After some googling, I guess this isn't directly possible. However, are there common tools to emulate this rather simply?



What are your thoughts?


More From » javascript

 Answers
9

No, you can't and even if there is a way you shouldn't. JavaScript is a dynamically typed language. For auto completion you can however use JSDoc style documentation tags that give some type pointers:



var Person = {
/**
* Say hi
* @param {String} name The name to say hi to
* @return {String}
*/
sayHi : function(name)
{
return 'Hi ' + name;
}
}


If they are being used depends entirely on your IDE though.


[#86722] Monday, March 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lonnier

Total Points: 621
Total Questions: 113
Total Answers: 98

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
;