how to sequence parameters in javascript functions -
i writing code in javascript.
colormixer = function (redintensity, blueintensity, greenintensity) { // mix color } colormixer(10, 8, 7) // means red = 10, blue = 8, green = 7 colormixer(10, 8) // means red = 10, blue = 8 question: how specify red = 10, green = 8, , no value blue (i dont intend 0 value blue) want scene value blue unknown , dont want provide value blue.
without changing calling method or function definition, can use undefined.
colormixer(10, undefined, 8); and, test each parameter see if it's undefined within function see if passed. use null indicator parameter not passed, prefer undefined because can leave off trailing arguments don't intend pass , automatically undefined.
but, if regular occurence, can change parameters passed in object , function can examine passed. more extensible because works equally no matter how many possible arguments there are:
colormixer({red: 10, blue: 8}); then, in colormixer function itself, @ properties on passed object , can see , wasn't passed.
Comments
Post a Comment