Interfaces can also be used to describe the shape of functions , That is, the parameter list describing the function , And return value type :
interface phoneCall{// Define a function type interface for making calls , It is agreed that this function needs a string Parameters of type , Then the return value type is void
(phoneNumber : string):void; }; let makePhoneCall:
phoneCall;// Define a phoneCall Variables of interface type function iphone(phoneNumber :
string):void{// Definition passed iphone Call function console.log("phone call to ", phoneNumber, "by
iphone"); } function android(number : string):void{// Definition passed android Call function
console.log("phone call to ", number, "by android"); } makePhoneCall =
iphone;// Will function iphone Interface variables assigned to function types makePhoneCall("12345");// Call function through function type interface function , output :phone
call to 12345 by iphone makePhoneCall = android;// Will function android Interface variables assigned to function types
makePhoneCall("67890");// Call function through function type interface function , output :phone call to 67890 by android
You can combine object type interfaces with function type interfaces :
interface phoneCall{// Define function type interface (phoneNumber : string) : string; }; interface
Human{// Define object type interface , Object contains a phoneCall Properties of type name : string, makePhoneCall : phoneCall
}; function humanMakeCall(data : Human, number: string) {
console.log(data.name, data.makePhoneCall(number)); } function
iphone(phoneNumber : string) : string{ return "phone call to " + phoneNumber +
" by iphone"; } function android(number : string) : string{ return "phone call
to " + number + " by android"; } let xiaoMing = { name : "XiaoMing",
makePhoneCall : iphone }; let xiaoHong = { name : "XiaoHong", makePhoneCall :
android }; humanMakeCall(xiaoMing, "12345");// output :XiaoMing phone call to 12345
by iphone humanMakeCall(xiaoHong, "67890");// output :XiaoHong phone call to 67890 by
android

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?