Constructor

Posted on under Javascript

Last updated on Originally published on

Collected under Programmings

Javascript is inherently a classless object-oriented language, so performing a lot of the things we’re used to in say, PHP, doesn’t work the same way. This doesn’t mean that these things are impossible though. In fact, Javascript is extremely open-ended and very fluid in how it implements OOP. So what if we need to extend the existing functionality of a function of an object, effectively replicating method inheritance?

Latest commit: a4b94c9 Utilizing new background images

Posted on under PHP

Last updated on Originally published on

Collected under Programmings

With version 5.4.0 of PHP, came something called traits. Granted, this is a fairly new version of PHP so there’s a good chance most developers won’t be using it on a live server for at least another 25 years, but it’s still good to learn about these kinds of things.

Similar to extending classes with child classes, traits allow you to share code, functionality, and variables between objects. The difference here is that sharing code via classes only allows you to share vertically. That is, you have to create and use a strict hierarchy of classes if you want to share code with all of them. This often creates “pyramids” of classes where every class is based on some highly basic originating class. This structure can be fine, but it’s not always appropriate from a taxonomical perspective. Traits, on the other hand, allow you to share code horizontally, meaning that there doesn’t need to be any explicit relationship between the objects.

Latest commit: a4b94c9 Utilizing new background images