[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

classes, prototypes and ???

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 8
Thread images: 1

File: 62935048.jpg (101KB, 1000x483px) Image search: [Google]
62935048.jpg
101KB, 1000x483px
There are classes like
class MyClass {
someAttribute;
method someMethod() {
// ...
}
};

myObject = MyClass ();


and there are prototypes like
myPrototype = 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.
Thread posts: 8
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.