         (println (str "var " name " = null;"))
         (doseq [[n meth] ms]
           (println (str "var " n " = " (with-out-str (emit-fn-method meth)) ";")))
-        (println (str name " = function(" (comma-sep maxparams) "){"))
+        (println (str name " = function(" (comma-sep (if variadic
+                                                       (concat (butlast maxparams) ['var_args])
+                                                       maxparams)) "){"))
+        (when variadic
+          (println (str "var " (last maxparams) " = var_args;")))
         (println "switch(arguments.length){")
         (doseq [[n meth] ms]
           (if (:variadic meth)

(defmethod emit :def
  [{:keys [name init env]}]
  (when init
    (print name)
    (print (str " = " (emits init)))
    (when-not (= :expr (:context env)) (print ";\n"))))

(defn emit-fn-method
  [{:keys [gthis name variadic params statements ret env recurs]}]
  (emit-wrap env
             (print (str "(function " name "(" (comma-sep
                                                (if variadic
                                                  (concat (butlast params) ['var_args])
                                                  params)) "){\n"))
             (when gthis
               (println (str "var " gthis " = this;")))
             (when variadic
