Javascript 如何在javascript中实现接口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11517134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:08:17  来源:igfitidea点击:

How to implement interface in javascript

javascript

提问by user1365697

Is it possible to implement interface in javascript

是否可以在javascript中实现接口

if yes do you have any example ?

如果是的话,你有什么例子吗?

回答by yusufaytas

First of all, there is not built in support for traditional abstraction in JavaScript. At least, there are not any types like interfaces and abstract classes. However, interface can be implemented using Object.create method and prototypes. For more information, visit here.

首先,JavaScript 中没有对传统抽象的内置支持。至少,没有任何类型,如接口和抽象类。但是,接口可以使用 Object.create 方法和原型来实现。如需更多信息,请访问此处

回答by PraveenVenu

Quoting from an article written by Mark McDonnell:

引用 Mark McDonnell 撰写的一篇文章:

In JavaScript there are no true "classic" Object-Oriented features, but through clever usage of the language you can emulate an Interface for use with a JavaScript API.

在 JavaScript 中没有真正的“经典”面向对象特性,但是通过巧妙地使用该语言,您可以模拟接口以与 JavaScript API 一起使用。

See the following for the complete article:

有关完整文章,请参阅以下内容:

http://www.javascriptbank.com/how-implement-interfaces-in-javascript.html

http://www.javascriptbank.com/how-implement-interfaces-in-javascript.html