What about a closure in the param list that refers to a param later in the list?
function foo(bar = function() { return x; }, x = 1) {
return bar();
}
foo(); // throws or 1?
I'm inclined to think that's fine because it's equivalent to:
function foo() { | |
var a = []; | |
for (var i = 0; i < 20000000; i++) { | |
a.push({}); | |
} | |
} | |
function repeat() { | |
printMem('before alloc'); | |
foo(); |
var spawn = require('child_process').spawn; | |
var csp = require('js-csp'); | |
class Math { | |
constructor(readyCallback) { | |
this._readyCallback = readyCallback; | |
this._worker = spawn('6to5-node', ['worker.js']); | |
this._worker.stderr.pipe(process.stderr); | |
this._reqChan = csp.chan(); |
/* @flow */ | |
class Foo { | |
n: ?number; | |
test(): boolean { | |
var n = this.n; | |
if (n == null) { | |
return false; | |
} else { |
/* @flow */ | |
// This works: | |
class Foo { | |
test(n: ?number): boolean { | |
if (n == null) { | |
return false; | |
} else { | |
return n > 10; | |
} |
What about a closure in the param list that refers to a param later in the list?
function foo(bar = function() { return x; }, x = 1) {
return bar();
}
foo(); // throws or 1?
I'm inclined to think that's fine because it's equivalent to:
#lang racket | |
(require 2htdp/image | |
2htdp/universe) | |
; Cell object. | |
(define make-cell | |
(lambda (x y) | |
(list (list x y) #f))) |
(function () { | |
var debounce = function (fn, d) { | |
var t; | |
return function () { | |
if (t) clearTimeout(t); | |
t = setTimeout(fn, d); | |
}; | |
}; | |
var giffy = function () { | |
[].slice.apply(document.querySelectorAll('a')).filter(function (a) { |
function cons (a, b) { | |
return function (sel) { | |
return sel(a, b) | |
} | |
} | |
function car (l) { | |
return l(function (a, b) { | |
return a | |
}) |
var adam = Proxy.create({ | |
get: function (rec, message) { | |
var firstname = "Adam"; | |
var lastname = "of Eden"; | |
switch (message) { | |
case "getName": | |
return firstname + " " + lastname; | |
default: | |
throw "unknown message " + message; | |
} |
// requires underscore.js for `_.clone`, although come to think about it could be done without it. | |
// The router module. | |
var router = (function () { | |
// Get the location array and filter out empty strings. | |
var path = window.location.pathname.split('/').filter(Boolean) | |
// The param arg stack. | |
, arg_stack = []; |