-8

I could see interface,extends,declare keywords has been used in java script libraries

lib.d.ts

as we use in Java.

For example

interface HTMLObjectElement extends HTMLElement, GetSVGDocument { }

Why we can't use those keywords when we would like to apply oo design patterns to Javascript appliccations like Node.js

vijaym
  • 41
  • 8
  • 2
    For starters, `.d.ts` are [TypeScript](http://www.typescriptlang.org/) definitions. Also you'll find with a bit of reading about ES6 that many of those features are being introduced. – Marty Nov 17 '15 at 10:34
  • 1
    Because JavaScript isn't a classical OO language. It's uses [prototypal inheritance](http://stackoverflow.com/questions/186244/what-does-it-mean-that-javascript-is-a-prototype-based-language). – Phylogenesis Nov 17 '15 at 10:34
  • Javascript is prototype based language and not object oriented language. That#s why we can not use it. – Srijani Ghosh Nov 17 '15 at 10:37
  • I don't understand why I got so much down vote ? – vijaym Nov 17 '15 at 10:42
  • Because the question is mostly about a subjective viewpoint. "Why doesn't language X do Y?" often has no good answer other than "Because it doesn't". – Phylogenesis Nov 17 '15 at 10:45

1 Answers1

1

That is a typescript type definition file.

In order to use the same keywords you will need to code your Node.js application on Typescript and have a compiler that transform it into valid javascript.

Juan
  • 3,675
  • 20
  • 34
  • 1
    Note it's possible to use the new ES6 keywords like `class` in a Node environment. – Marty Nov 17 '15 at 10:37
  • Yeah I was going to suggest ES6 too but I am not really familiar with it and a quick search show my that "interface" doesn't seem to be supported. So I went for the typescript answer. But a really valid note! – Juan Nov 17 '15 at 10:38
  • @Marty Yes, ES6 has some OO-like syntactic sugar. That is, in a kinda sorta don't look too closely type of way. – Phylogenesis Nov 17 '15 at 10:39
  • @Phylogenesis As you say, it is important to note that though I have mentioned keywords like `class` exist in ES6 it does not mean that they work in a traditional manner. They still produce typical JavaScript "inheritance". – Marty Nov 17 '15 at 10:41