In JavaScript a nested type can read and assign variables from outer scopes.
function counter(start = 0) {
let n = start;
class Counter {
peek() { return n; }
increment() { ++n; }
}
return new Counter();| def histogram(nums, n_buckets, title): | |
| min_val = min(*nums) | |
| max_val = max(*nums) | |
| buckets = [] | |
| bucket_width = (max_val - min_val) / float(n_buckets) | |
| while (len(buckets) < n_buckets): | |
| buckets.append(0) | |
| sum_of_values = 0 | |
| for num in nums: | |
| sum_of_values += num |
| Matching code-units that have all the same size OK. | |
| applying /a/ to '"aό𝄞"' | |
| . py UTF-8 | |
| . . 00000000 61 |a| | |
| . . 00000001 | |
| . js UTF-16 | |
| . . 00000000 61 |a| | |
| . . 00000001 | |
| . py UTF-32 | |
| . . 00000000 61 |a| |
| <!doctype html><meta charset=utf-8> | |
| <!-- this file is subjectivity.html --> | |
| <script> | |
| // Just calls a method on the string it's given. | |
| // Below each iframe locally overrides that method. | |
| window.makeItBold = (str) => str.bold(); | |
| // We're loading the same HTML in three frames so fork. | |
| switch (window.location.hash) { |
| function cmpNums(a, b) { | |
| if (Object.is(a, b)) { return 0; } | |
| let delta = a - b; | |
| if (delta) { | |
| return Math.sign(delta); | |
| } else if (delta === 0) { | |
| // The only values that do not match Object.is above | |
| // and which do not lead to a NaN delta are -0, +0 | |
| // and vice versa. | |
| return Object.is(a, -0) ? -1 : 1; |
In JavaScript a nested type can read and assign variables from outer scopes.
function counter(start = 0) {
let n = start;
class Counter {
peek() { return n; }
increment() { ++n; }
}
return new Counter();| import java.lang.reflect.*; | |
| import java.util.*; | |
| public class Foo { | |
| public static void main(String[] argv) throws Exception { | |
| Class<?> integerCacheClass = Arrays.stream(Integer.class.getDeclaredClasses()) | |
| .filter(c -> c.getSimpleName().equals("IntegerCache")) | |
| .findFirst() | |
| .get(); | |
| Field cacheField = Arrays.stream(integerCacheClass.getDeclaredFields()) |
| // Run in the context of a HostEnsureCanCompileStrings callout that | |
| // throws an EvalError (from the callee realm) for string values, and | |
| // arrays. | |
| const PASS = {}, FAIL = {}; | |
| function tryCompileAsFunctionBody(description, source, expectedStatus) { | |
| let status = FAIL; | |
| try { | |
| new Function(source); |
| // On the server | |
| response.write(x); | |
| // On the client | |
| document.body.innerHTML = x; |
| <script>/**/alert('svg');//*/alert('html'); | |
| //<![CDATA[</script><!--]]>--></script> | |
| <svg> | |
| <script>/**/alert('svg');//*/alert('html'); | |
| //<![CDATA[</script><!--]]>--></script> | |
| </svg> |
| class TrustedScript { // Just a stub of github.com/wicg/trusted-types | |
| constructor(x) { | |
| this.content = String(x); | |
| } | |
| toString() { | |
| return this.content; | |
| } | |
| static createUnsafely(x) { |