I am developing an OOP inheritance pattern for many of the applications that I create. Javascript has many ways to do this, but I came across a sample that I really like. But now I'm struggling with the need to separate classes and instances.
I have a basic Root object. And it has a main method called inherit. To create a new object, you use
var Person = Root.inherit({
name : "",
height : 0,
walk : function() {},
talk : function() {}
});
Then, to create an "instance", you would
var sally = Person.inherit({
name : "sally",
height : "5'6"
});
sally can .talk (), and she can walk (), and she has .name and .height You can make more people the same.
If you want to use the constructor you use
var Person = Root.inherit({
_construct : function() {
},
name : "",
height : 0,
walk : function() {},
talk : function() {}
});
It also has the ability to have init when the object is first defined in code (use one-dot)
var Person = Root.inherit({
_init : function() {
},
name : "",
height : 0,
walk : function() {},
talk : function() {}
});
, , .inhert(). . - . , , , "", , . "", "" , .
, : javascript ? - ?