0

Is there native javascript functionality for protected functions?

I want to be able to extend multiple prototypes and avoid accidentally overriding methods.

To make it more strict...

Somebody
  • 9,316
  • 26
  • 94
  • 142
  • @Gothdo The question was wrongly marked as duplicate. It concerns property descriptors, not visibility. – Estus Flask Nov 13 '16 at 15:02
  • @estus What do you mean? [The answer in the question "Access Modifiers (Private, Protected) in ES6"](http://stackoverflow.com/a/34834120/3853934) says that protected methods are not possible in JavaScript, and that answers this question. – Michał Perłakowski Nov 13 '16 at 15:44
  • @Gothdo OP asks for specific thing, *avoid accidentally overriding methods*, depending on the situation this can be possibly solved with property descriptors. This doesn't conform to the purpose of 'protected' access modifier, it looks like the term was used literally. While the question may need improvement and can be a duplicate of another question, it doesn't look like an exact duplicate of that one. – Estus Flask Nov 13 '16 at 15:56
  • @estus If this question is about preventing overwriting methods, then it's a duplicate of [Is there any way to prevent override/overwrite of functions/variables in singleton instance?](http://stackoverflow.com/q/14671332/3853934). – Michał Perłakowski Nov 13 '16 at 16:01
  • @Gothdo Not sure if this fits *extend multiple prototypes* requirement. Any way, I think that OP should have a chance to elaborate what exactly is his/her case before prematurely marking it as dupe. – Estus Flask Nov 13 '16 at 16:10
  • I was looking for native feature to get exception if some class prototype method is overriding some other prototype method. Something like compilation errors etc. Like code validation tools are working. Like jslint or something like that. To make it more friendly for future devs. – Somebody Nov 13 '16 at 17:27
  • 1
    @Somebody The word 'protected' isn't applicable here. This is called 'final method' in OOP. JS doesn't support this kind of restriction on design time (neither with linters, nor with Typescript, afaik). This behaviour can be forced on run time with property descriptors, however, I wouldn't recommend it, because it causes more problems than it solves (at the very least, this would hurt testing). If you're interested in getting an answer, I would suggest to create a new question for that (code is also necessary in this type of question, it isn't something that should be described with words). – Estus Flask Nov 13 '16 at 18:21

0 Answers0