Are Interfaces in JavaScript necessary?

前端 未结 5 1080
再見小時候
再見小時候 2021-02-04 00:31

I suppose this could apply to any dynamic language, but the one I\'m using is JavaScript. We have a situation where we\'re writing a couple of controls in JavaScript that need t

5条回答
  •  余生分开走
    2021-02-04 01:22

    Since you can call any method on any object in a dynamic language, I'm not sure how interfaces would come into play in any truly useful way. There are no contracts to enforce because everything is determined at invocation time - an object could even change whether it conforms to a "contract" through its life as methods are added and removed throughout runtime. The call will fail if the object doesn't fulfill a contract or it will fail if it doesn't implement a member - either case is the same for most practical purposes.

提交回复
热议问题