Set type for function parameters?

后端 未结 12 1821
醉话见心
醉话见心 2020-11-30 18:37

Is there a way to let a javascript function know that a certain parameter is of a certain type?

Being able to do something like this would be perfect:



        
12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 19:11

    Not in javascript it self but using Google Closure Compiler's advanced mode you can do that:

    /**
     * @param {Date} myDate The date
     * @param {string} myString The string
     */
    function myFunction(myDate, myString)
    {
        //do stuff
    }
    

    See http://code.google.com/closure/compiler/docs/js-for-compiler.html

提交回复
热议问题