oop - Is JavaScript object-oriented? -
there have been questions whether or not javascript object-oriented language. statement, "just because language has objects doesn't make oo."
is javascript object-oriented language?
imo (and opinion) the key characteristic of object orientated language would support polymorphism. pretty dynamic languages that.
the next characteristic encapsulation , pretty easy in javascript also.
however in minds of many inheritance (specifically implementation inheritance) tip balance whether language qualifies called object oriented.
javascript provide easy means inherit implementation via prototyping @ expense of encapsulation.
so if criteria object orientation classic threesome of polymorphism, encapsulation , inheritance javascript doesn't pass.
edit: supplementary question raised "how prototypal inheritance sacrifice encapsulation?" consider example of non-prototypal approach:-
function myclass() { var _value = 1; this.getvalue = function() { return _value; } }
the _value attribute encapsulated, cannot modified directly external code. might add mutator class modify in way entirely controlled code part of class. consider prototypal approach same class:-
function myclass() { var _value = 1; } myclass.prototype.getvalue = function() { return _value; }
well broken. since function assigned getvalue no longer in scope _value can't access it. need promote _value attribute of this
make accessable outside of control of code written class, hence encapsulation broken.
despite vote still remains javascript object oriented. why? because given ood can implement in javascript.
Comments
Post a Comment