There are classes likeclass MyClass {
someAttribute;
method someMethod() {
// ...
}
};
myObject = MyClass ();
and there are prototypes likemyPrototype = object {.
someAttribute = "some value";
method someMethod() {
// ...
}
};
myObject = myPrototype.clone();
myObject.addMethod(method anotherMethod(){
// ...
});
But what is it called when every object is created from scratch without prototype inheritance and duck typing instead?
>>61658368
first and only bump
> not using C
>>61658368
It all depends on the programming language. The basic "class" is simply a bunch of data structure and some methods to operate on them. The idea is to avoid dublicate code (you can simply create an object of the class), to hide information from "outside maipulation" (by allowing only certain mathods to operate on the data) and to get more coherence by binding data togeter, that belongs together.
But languages have many slightly different concepts. For example in C you can have a struct with function pointers, which is "almost" like a class. Or in Ruby each class is also an object, so it's more like an Prototype, but with some things a normal prototype in something like JavaScript can't do..
Each language of those will look at classes/objects in a different way.
>what is it called when every object is created from scratch without prototype inheritance and duck typing instead?
Could you give an example here? To me that sounds like a simple Class/Object relationship..
>>61658887
It's mostly for scripting languages.
Also:
>using a brainlet language for actual programming
>>61658958
>Could you give an example here? To me that sounds like a simple Class/Object relationship..
Something like// those could be part of fabric functions:
myObject = object {
someVariable = 2;
someMethod() {
// does something
}
};
myOtherObject = object {
someMethod() {
// does something else
}
};
function doSomething(x) {
x.someMethod();
}
// different output
doSomething(myObject);
doSomething(myOtherObject);
Basically what most sane JS programmers do most of the time, since prototypes aren't that particulary useful in most scenarios.
>>61658368
>>61659023
I don't think there's an actual name for doing this
I guess you could describe it as simple object polymorphism?
>>61660420
>I guess you could describe it as simple object polymorphism?
Probably.