Jan 12
Veel thee drinken, diep ademhalen en doorgaan
Jan 12
Javascript parent constructor being run when defining inheritance and a solution
When using the traditional Javascript methods to do some sort of inheritance, the constructor of the parent will always be run when trying to inherit it. This seems to be a unfortunate side effect of using new a().
The problem
Consider this code. Here b inherits from a
function a() { console.log("a"); } function b() { a.call(this); console.log("b"); } b.prototype = new a(); // a's constructor will be run here! b.prototype.constructor = b; new b(); // run once new b(); // run twice
Here a’s constructor will be run 3 times.
a a b a b
The solution
There is a simple fix for this, but its only in Ecmascript 5.
Change this:
b.prototype = new a();
Into this:
b.prototype = Object.create(a.prototype);
And the constructor will only be run when actually being called:
a b a b
Jan 12
Using hgtools with mercurial tags to automatically version packages
I liked to automate my python package versioning a bit more and did this with hgtools. With hgtools it is quite easy to store the version numbers only in your repository as tags, and not having it again in setup.py.
A minimal setup.py can look like this:
from setuptools import setup, find_packages setup( name="HelloWorld", use_hg_version=True, packages=find_packages(), setup_requires=["hgtools"], )
Just give a revision a tag and make an sdist, or bdist and setuptools will use the version from your tag.
Tags have to conform to strict version formatting from distutils to be used by hgtools.
Later I also made it a step in a Jenkins setup, to always build a sdist and copy it to a HTTP accessible directory so it could be installed with pip. This gave me a nice history of available release packages and also, dev versions.
Jan 12
Wekelijks bezoekje aan de weegschaal
Jan 12
Hormoonmonsters
Dec 11
Jaarafsluiting
Dec 11