1

So, I'm a big fan of using interfaces in Java. I am trying to relate that to AngularJS. I read up on the concept of duck typing for Javascript, which is fairly straightforward. Is there anything the base AngularJS library provides in addition to that that would be similar to the concept of an interface? I know javascript is loosely typed, but without using typescript, is there anything similar?

I'm only familiar with AngularJS to the point that I can jump into existing code and change functionality, I am not able to develop a well designed Angular application from scratch. We are using Angular version 1.X.

1
  • The presupposition about TS doesn't give the question a chance. TypeScript is a superset of JavaScript that offers static typing. Obviously, it wouldn't be created if JS offered typing. So yes, it has interfaces and stuff, and actually makes the adoption of JS libraries that have typings easier. Angular is among them. TS-friendly IDE can help an Angular dev in writing more code and RTFMing less. Commented Aug 12, 2016 at 20:38

3 Answers 3

2

There's nothing angulary that would be similar to an Interface. You don't typically define an Interface in JavaScript, so most likely what you want to do is an anti-pattern in JavaScript.

Here's another SO question that digs into why duck typing isn't typically something you do with JavaScript.

Duck Typing in Javascript

Sign up to request clarification or add additional context in comments.

Comments

1

I'm sorry but TypeScript is what you should use. That's my opinion. AngularJS is more like a framework that helps you with Model View Controller. It is not a library and it doesn't extend JS in that way.

Comments

0

the best thing is using Typescript for interfaces. Because JavaScript doesn't have interfaces. Here Typescript will transpiles your code to resulting JavaScript. I think Interfaces are only for strong typing and better tooling support to build a code without any errors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.