ceninan: Jetrel: I was browsing my logs and saw this: "jetrel2: [nicks omitted] is there any sort of function overloading for different parameter sets in JS?" [8:58pm] ceninan: Technically, yes. [8:59pm] ceninan: function arity() { return arity[arguments.length].apply(this, arguments); } [8:59pm] ceninan: arity[0] = function () { console.log("arity 0"); }; [8:59pm] crimson_penguin: that's just awful [8:59pm] ceninan: crimson_penguin: of course it is [9:00pm] ceninan: crimson_penguin: even more so because there's absolutely no checks or convenience to fit on a single line :P [9:00pm] ceninan: crimson_penguin: you can do "fun" stuff such as dispatching based on the day of the week though! [9:01pm] crimson_penguin: heh, indeed [9:01pm] ceninan: AKA calling 'do_work()' on a Monday would throw a "NotInMoodError" [9:03pm] ceninan: Anyway; Yes, it's possible. In Lua you almost expect people to roll their own object systems; Clojure has ad-hoc dispatch much like this built-in. [9:04pm] ceninan: In Javascript it's probably better not to :) [9:06pm] ceninan: http://jsfiddle.net/5dZQA/ [9:07pm] ceninan: (If for some reason I'd want to do it, I think I would go for per-function ad-hoc dispatch though) [9:08pm] DDR: The problem with function args is that they could be almost anything. [9:08pm] DDR: Just, in general like. [9:08pm] DDR: For example, draw(bar), what does 'bar' mean? [9:09pm] DDR: draw({'from': bar}) is clearer. [9:09pm] DDR: Albeit more verbose. [9:11pm] ceninan: DDR: sure, but nothing stops you from looking at the "from:" attribute and dispatching on that [9:11pm] DDR: No, not at all. [9:11pm] ceninan: I think JS is limited to string keys (unlike Lua), but that's about it [9:11pm] Krista^: crimson_penguin: need to rework the on-screen control positions for android [9:12pm] DDR: It's clearer if, when you're having 'optional args', if the arg isn't dependant on place. [9:12pm] DDR: Or number of args. [9:13pm] DDR: For example, for Editabled, the editable pixel editor, I've got some drawing functions which can take three or four optional parameters. I pass a map to those, because I don't have to keep track of the count then. [9:14pm] DDR: It's stupid, I think, but it solves the need for the ugly arity check. [9:14pm] DDR: :/ [9:15pm] ceninan: function look_inside() { return look_inside["from: " + arguments[0].from].apply(this, arguments) } [9:15pm] ceninan: look_inside["from: bar"] = function () { console.log("Came from bar!"); }; [9:15pm] ceninan: look_inside({from: bar}); // prints "Came from bar!" [9:15pm] ceninan: and that's enough code spam :\ [9:16pm] DDR: ow