Skip to content

Experience with d3.js – Bram

by on October 24, 2012

Most of what Geert said is true:

  • Chaining rocks! I’ve noticed this already when writing PHP with ZF2, which also allows chaining of methods. Writing “obj.method().method2();” is way shorter than “obj.method(); obj.method2();”. There is, however, a downside. If I run “obj.method().method2()”, who’s to say what the type of the return value of “obj.method()” is? Is it obj itself (this is how ZF2 uses chaining) or is it an entirely other object? d3.js uses the latter aproach, which can be confusing in my opinion.
  • var vs function: In javascript, variables can also be functions. As I’ve said in the class last week, this can be quite confusing. You expect a variable to actually represent a basic type or an object (cf. Java). Or, if you’re into C++, you’d expect the type of the variable to be different if it’s a function.
    However, as javascript uses “var” instead of strongly typed variables, there’s no distinguishable difference between an object or a function as variable.
    As I am writing most of my work in (derivatives of) C and/org Java, I’m used to strong typing. This way of working with functions took a time to fully understand.

My examples can be found here and here.

From → Uncategorized

3 Comments
  1. erikduval permalink

    Might be good to also do an interactive example – so that you are well prepared for the marathon this weekend?

  2. The links to the two examples seem broken.

Leave a reply to bramgotink Cancel reply