oop - Javascript way to design inheritance + privacy -


i read book "javascript : parts" book douglas crockford , many other resources , i'm bit confused implementing inheritance , privacy in javascript.

i'm coming java world, i've understood can simulate privacy via closure, or doing inheritance via prototype want in javascript way.

i know can perform inheritance prototypal / parasitic pattern. performance there no way use privacy members (without creating closure function each time new object instanciated)

i know can inherit object , use privacy members via functionnal / parasitic pattern such suggested douglas crockford there obvious performance / memory issue since functions created again each time object instanciated.

finally i'm wondering if practices in other language such privacy encapsulation make sense in javascript. i've seen post here people said "we don't care privacy, tell world property should not accessed outside , that's enough".

should consider practices in javascript reduced prototypal / parasitic inheritance, public interface , hope developpers use library expected ? or maybe thinking in terms of inheritance , encapsulation "java" way think , not javascript 1 ? how use power of duck programming in javascript achieve these goals ?

i disagree things in book , find them poorly argumented. if not that, of them utterly irrelevant due strict mode , modern tools jshint. guess problem how outdated book is, since these not available @ time.

the language's object model extended in 2009 plenty of new features , methods made difference between variables , properties larger. if possible 10 years ago pretend variables properties, not now.

the communicate not part of published api, underscore prefix used like:

this._age = 5; this._method(); 

this might have special meaning modern ides doesn't have special meaning reflective methods in language for..in , getownpropertynames.

there plenty of tutorials , guides on how use natural* constructor prototype pattern express concept of class.

*the definition of natural use means javascript engines recognize , optimize for.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -