Signature (functions)

函数签名(或者类型签名,抑或方法签名)定义了 函数方法的输入与输出。

签名可包含以下内容:

  • 参数 及参数的 类型
  • 一个的返回值及其类型
  • 可能会抛出或传回的exceptions
  • 该方法在 面向对象程序中的可用性方面的信息(诸如publicstaticprototype等关键字等

深入

JavaScript中的签名

JavaScript 是一种类型松散(loosely typed)的或者说动态语言。那就是说不必提前声明变量类型(that means you don't have to declare the type of a variable ahead of time)。当程序被处理时,类型将得到自动确认。JavaScript中的签名,仍然能给你一些有关该方法的一些信息:

MyObject.prototype.myFunction(value)
  • 该方法是安装在一个名为MyObject对象上的(the method is installed on an object called MyObject)。
  • 该方法是安装在MyObject的原型上的(installed on the prototype of MyObject, 因此其是一个实例方法),而不是作为一个静态方法进行安装的。
  • 该方法的名字为myFunction
  • 该方法接受一个参数,该参数被命名为value,且没有进一步定义。

Signatures in Java

In Java, signatures are used to identify methods and classes at the level of the virtual machine code. You have to declare types of variables in your code in order to be able to run the Java code. Java is strictly typed and will check any parameters at compilation time if they are correct.

public static void main(String[] args)
  • The public keyword is an access modifier and indicates that this method can be called by any object.
  • The static keyword indicates that this method is a class method as opposed to being an instance method.
  • The void keyword indicates that this method has no return value.
  • The name of the method is main.
  • The method accepts one parameter of type String Array. It is named args.

Learn more

General knowledge

文档标签和贡献者