30
max-dng
8y

How my lecturer drilled JS syntax into us:

Write this:
var x = document.element;
x.value = 10;

Instead of this:
document.element.value = 10;

His reasoning:
"You make the cake in the kitchen, you don't put icing on it on your way to present the cake"

Comments
  • 9
    Then I guess the whole idea of a 1-liner is going in the trash can...
  • 12
    In this case, you're not baking the cake (document.element). All you're doing is adding the icing (value = 10). So basically, he's saying go and get the ready-made cake from your fridge, go and put it in the bathroom, ice it in there and then present it.

    Oh man, I just spent far too much time on this...
  • 1
    This is a one-step cake though. I agree with it if there's a couple things you wanna do but its just wasteful otherwise.
  • 0
    With that logic he should do

    var d = window.document
Add Comment