profile
viewpoint
Douglas Crockford douglascrockford Virgule-Solidus San Jose https://www.crockford.com I was born in Frostbite Falls, Minnesota. I left when I was 6 months old because it was too damn cold. My latest book is _How JavaScript Works_.

douglascrockford/JSON-js 8099

JSON in JavaScript

douglascrockford/JSLint 3350

The JavaScript Code Quality Tool

douglascrockford/DEC64 854

Decimal floating point

douglascrockford/JSMin 587

JavaScript Minification Filter

douglascrockford/JSCheck 541

A random property testing tool for JavaScript

douglascrockford/ADsafe 227

A safe JavaScript widget framework for advertising and other mashups.

douglascrockford/howjavascriptworks 183

Programs from the book _How JavaScript Works_

douglascrockford/TDOP 136

Top Down Operator Precedence

douglascrockford/parseq 134

Better living thru immediacy!

douglascrockford/fulfill 90

Safer, more cosmopolitan string interpolation.

push eventdouglascrockford/Programma

Douglas Crockford

commit sha f5f1435f986bef7bb8fd528262297955de214dc9

suit width

view details

push time in 7 days

push eventdouglascrockford/Programma

Douglas Crockford

commit sha 031ac8c0361ec49238e2bd9d2484162b36564a9e

suits

view details

push time in 7 days

push eventdouglascrockford/JSLint

Douglas Crockford

commit sha 95c4e8a2cfd424d15e90745dbadadf3251533183

FontFace

view details

push time in a month

pull request commentdouglascrockford/JSLint

globalThis has reached stage 4 - https://github.com/tc39/proposal-global

Every bad practice that JSLint warns against is useful.

kaizhu256

comment created time in 2 months

pull request commentdouglascrockford/JSLint

globalThis has reached stage 4 - https://github.com/tc39/proposal-global

That is appallingly stupid. Thanks for the heads up.

kaizhu256

comment created time in 2 months

issue commentdouglascrockford/JSLint

allowed_option and options are not synced on startup

I am sorry, I need more information. What exactly is the problem?

harish988

comment created time in 2 months

issue commentdouglascrockford/JSON-js

Failing to parse this valid JSON

It is not safe to add stuff to the system's prototypes. A better solution is to use JSON.stringify. Happy new year.

stephen147

comment created time in 2 months

push eventdouglascrockford/Programma

Douglas Crockford

commit sha 320662f406f0fcd243cc551430a354642794da7b

U+00AC NOT SIGN

view details

push time in 2 months

push eventdouglascrockford/Programma

Douglas Crockford

commit sha c80bcc26d5269c7e9544269f1fb5b4ce46d5812c

U+00AC NOT SIGN

view details

push time in 2 months

push eventdouglascrockford/Programma

Douglas Crockford

commit sha d4bcd29ca139e191ef13085be8b75860db181bfd

U+23E8 decimal exponent symbol

view details

push time in 2 months

push eventdouglascrockford/JSLint

Douglas Crockford

commit sha 0ac7d71be20f8620e068b1d1ce3ff1784fc5660d

CharacterData, DocumentType

view details

push time in 2 months

push eventdouglascrockford/JSLint

Douglas Crockford

commit sha 72347f0cf08d7a6ba6d3967b1d96a0009a0d6988

fetch, IntersectionObserver

view details

push time in 2 months

push eventdouglascrockford/Programma

Douglas Crockford

commit sha d80565239653f1bb2f7901834e2ffa95233024cf

{}

view details

push time in 3 months

issue closeddouglascrockford/JSMin

Broken link on documentation site

The link to "jsmin.exe: JSMin prebuilt for MS-DOS" ( http://www.https//www.crockford.com/javascript/jsmin.zip ) on https://www.crockford.com/jsmin.html is broken

closed time in 3 months

cowlinator

issue commentdouglascrockford/JSMin

Broken link on documentation site

Thanks.

cowlinator

comment created time in 3 months

push eventdouglascrockford/JSMin

Douglas Crockford

commit sha 7d7aea259acaa8fe61d09d168a004ed9a8dd072a

jsmin.exe

view details

push time in 3 months

push eventdouglascrockford/Programma

Douglas Crockford

commit sha 05eeead8376fede4145dbd043b128362a362932d

florin

view details

push time in 3 months

issue closeddouglascrockford/howjavascriptworks

How to handle floating-point array indices in Neo?

Dear Mr. Crockford, I like your idea of combining floats and ints into one number type. One unified number type makes sense for most math operations and saves a lot of headache associated with handling two number types. However, when we are doing array indexing, how can we handle floating-point indices? I know that all array indices in JavaScript are strings so you can store values into floating-point indices:

let a = []
a[1.5] = 10
console.log(a[1.5]) // outputs: 10

To me, JS's behavior is both strange and confusing as many people including me regard array indices as whole numbers and expect JS to floor or round floating-point indices to whole numbers. What approach do you recommend to deal with floating-point indices? Is this a necessary evil for adopting a unified number type?

closed time in 3 months

AlienKevin

issue commentdouglascrockford/howjavascriptworks

How to handle floating-point array indices in Neo?

I agree that JS is much too permissive here. Strings should not be used as array indexes. On reading, a[1.5] should produce null because there is no such element. On writing, it should fail.

AlienKevin

comment created time in 3 months

CommitCommentEvent

pull request commentdouglascrockford/howjavascriptworks

Update neo.runtime.js

I have adopted your suggestion. Thanks.

GHDIShfdiod876dhs

comment created time in 4 months

push eventdouglascrockford/howjavascriptworks

Douglas Crockford

commit sha 80ae6b0186ee0fa1a43d88cfbdb0074be6cddf33

Thanks, Chris Schroeder

view details

push time in 4 months

push eventdouglascrockford/DEC64

Douglas Crockford

commit sha b5f5bdd624d20e6f1af4206a51b9ce95a230aa16

comments

view details

push time in 4 months

issue commentdouglascrockford/JSMin

Regular expression literal can have its whitespace removed

I think this is fixed in the latest.

Why are you minifying minified code?

li-a

comment created time in 4 months

push eventdouglascrockford/JSMin

Douglas Crockford

commit sha 430bfe68dc0823d8c0f92c08d426e517cbc8de5e

newline slash

view details

push time in 4 months

issue closeddouglascrockford/JSMin

Unrecognized Regex Literals

Given this if statement, the following snippets aren't seen as regex literals by JSMin:

if (theB == '/' && (theA == '(' || theA == ',' || theA == '=' ||
                            theA == ':' || theA == '[' || theA == '!' ||
                            theA == '&' || theA == '|' || theA == '?' ||
                            theA == '{' || theA == '}' || theA == ';' ||
                            theA == '\n')) {

Snippet #1:

var ex = +/w$/.test(resizing),
    ey = +/^n/.test(resizing);

In this case, when "theB" == "/", "theA" == "+" which isn't one of the conditions defined.

Snippet #2:

return /[",\n]/.test(text)
      ? "\"" + text.replace(/\"/g, "\"\"") + "\""
      : text;

In this case, "theA" == " " because of the return.

closed time in 4 months

jaydiablo

issue closeddouglascrockford/JSMin

Unterminated Regular Expression Error except when comment on next line

With the latest update to JSMin I was able to get it to minify the d3.js library correctly, thanks again for that. So I decided to do a little work on the PHP port of JSMin to get it up to date with the latest release, however I ran into an inconsistency that I thought I would point out.

Once again, the d3 author(s) are doing something that JSLint doesn't recommend:

// Compute the angular scale factor: from value to radians.
var k = ((typeof endAngle === "function"
    ? endAngle.apply(this, arguments)
    : endAngle) - startAngle)
    / d3.sum(values);

Running JSMin on just this snippet will cause it to spit up the "Unterminated Regular Expression literal." due to the division operator being on its own line. Which made me question why/how it's getting through the whole d3.js file without encountering the same error. It appears to be because the next line in the file is a comment:

// Compute the angular scale factor: from value to radians.
var k = ((typeof endAngle === "function"
    ? endAngle.apply(this, arguments)
    : endAngle) - startAngle)
    / d3.sum(values);

// Optionally sort the data.

I believe that JSMin sees that first character of the comment line as the ending regex token, so doesn't complain in this situation.

closed time in 4 months

jaydiablo

issue commentdouglascrockford/JSMin

Unterminated Regular Expression Error except when comment on next line

Thank you. Please try the latest.

jaydiablo

comment created time in 4 months

push eventdouglascrockford/JSMin

Douglas Crockford

commit sha dc8f7c5a10451cab57eb75e6b9435f5c442ba900

s

view details

push time in 4 months

issue closeddouglascrockford/JSMin

Regular expression literal can have its whitespace removed

Consider this legal JS (found in highcharts 4.1.4, already apparently minified by Closure Compiler):

{dSetter:function(a,b,c){a&&a.join&&(a=a.join(" "));/(NaN| {2}|^$)/.test(a)&&(a="M 0 0");c.setAttribute(b,a);this[b]=a}}

JSMin outputs:

{dSetter:function(a,b,c){a&&a.join&&(a=a.join(" "));/(NaN|{2}|^$)/.test(a)&&(a="M 0 0");c.setAttribute(b,a);this[b]=a}}

The RegExp literal has been modified (| { --> |{, which also happens to be invalid syntax).

Seems to be distinct from #11 because testing across history indicates the problem was only introduced by cec896f0affaa0226c02605ad28d42df1bc0e393 (which is newer than #11).

closed time in 4 months

li-a

issue commentdouglascrockford/JSMin

Regular expression literal can have its whitespace removed

A problem I have had historically is that if one of my tools accepts code that is badly written, then it is assumed that 'I' am approving, which I am not. That is why made that change in 2012. Up until now, no one has complained.

There is a lot of stupid stuff happening in that highcharts code, but I am past caring about it. JSMin will now accept it.

li-a

comment created time in 4 months

push eventdouglascrockford/JSMin

Douglas Crockford

commit sha ba1e66da27fbb67c2701462c9046eec49bd3bd74

Be more forgiving of bad practices

view details

Douglas Crockford

commit sha b3063030d9626b0961dbc37619cbe881ea36f21d

hygiene

view details

push time in 4 months

PR closed douglascrockford/howjavascriptworks

Update neo.runtime.js

I think in order for the array constructor to work as intended, there needs to be logic checking if the first argument is an array and the second argument is a function. If so, the second argument is used as a mapping function across the first argument.

+3 -0

1 comment

1 changed file

GHDIShfdiod876dhs

pr closed time in 4 months

pull request commentdouglascrockford/howjavascriptworks

Update neo.runtime.js

Thanks for the suggestion. The functionality you are proposing is provided by map. I don't think it is necessary for array to do it too, although it makes some sense.

 If the argu­ment is an array, then make a shallow copy of the array. Addi­tional argu­ments can give the starting and ending posi­tions for copying a por­tion of the array.
GHDIShfdiod876dhs

comment created time in 4 months

startedbeltoforion/Galaxy-Renderer

started time in 4 months

push eventdouglascrockford/DEC64

Douglas Crockford

commit sha 3dc3a2dc44e8f0dbff68fadae63b5f77a520f0d9

x4

view details

Douglas Crockford

commit sha cd260a910cd46bd790c182a2bcb07a253821a246

80 columns

view details

push time in 4 months

issue commentdouglascrockford/JSON-js

Include the reference to NPM package in Readme

I have never posted anything to NPM.

michael-freidgeim-webjet

comment created time in 4 months

issue closeddouglascrockford/JSON-js

Include the reference to NPM package in Readme

Please include the reference to NPM package https://www.npmjs.com/package/json-js in Readme. Also can you please publish the latest version to NPM repository (last publish 4 years ago)?

closed time in 4 months

michael-freidgeim-webjet

issue commentdouglascrockford/JSON-js

Include the reference to NPM package in Readme

json2.js is one bitty file that won't change. NPM has profound, unsolvable secure problems. I do not recommend that anyone use it.

michael-freidgeim-webjet

comment created time in 4 months

issue closeddouglascrockford/howjavascriptworks

Function parsing seems to fail in Neo

I passed this source string to parse(tokenize(source))

def bar: f a {
    let a: a + 1
}

and parser returns an error object:

{ id: '(error)',
  zeroth:
   { id: 'f a',
     alphameric: true,
     line_nr: 0,
     column_nr: 9,
     column_to: 12 },
  wunth: 'expected a variable' }

Do I have the wrong function syntax or the parser breaks?

closed time in 4 months

AlienKevin

issue commentdouglascrockford/howjavascriptworks

Function parsing seems to fail in Neo

Use 'ƒ' to make functions.

AlienKevin

comment created time in 4 months

issue closeddouglascrockford/howjavascriptworks

How print() works in Neo?

Dear Mr. Crockford, How would you implement print() in Neo? Consider that we need to use call print() to ignore null return value and it can get quite verbose. Would you create a new keyword for printing like Python 2?

closed time in 5 months

AlienKevin

issue commentdouglascrockford/howjavascriptworks

How print() works in Neo?

Fortran had a print statement. C did the right thing in getting rid of it.

AlienKevin

comment created time in 5 months

issue closeddouglascrockford/JSON-js

BigInt support

I hope this doesn't go too far off with acceptable issue topics here, and if it does - my apologies.


I was looking for a solution that would support the new BigInt type within JSON.stringify, but nothing so far...

The existing implementation simply throws an error when encountering BigInt.

And when using a replacer function, like this one:

function toJson(data) {
    return JSON.stringify(data, (_, v) => typeof v === 'bigint' ? v.toString() : v);
}

We end up with all BigInt values wrapped into double quotes instead of being an open value.

Here's the the bigger problem that brought me here.

I am hoping to find something elegant, without the need of replacing the whole JSON.stringify, so maybe you can offer something from your extensive experience with this?

closed time in 5 months

vitaly-t

issue commentdouglascrockford/JSON-js

BigInt support

json2.js was intended to bridge the transition between ES3 and ES5, which it did, successfully. It is now at end of life and should no longer be used.

The problem you are encountering is using an (apparently) poorly designed proposed new language feature. I don't track the standards process any more, so I don't know if the problem is that your JS engine did not properly make matching changes to JSON methods, or if TC-39 failed to think through the consequences of their unnecessary bigint design.

I would avoid bigints until this gets sorted, if not longer. Meanwhile, send your complaints to ECMA.

vitaly-t

comment created time in 5 months

push eventdouglascrockford/DEC64

Douglas Crockford

commit sha 66ae06ca4c3482477bcd395f1805b6d8c03f38bd

less_hard

view details

push time in 5 months

PR closed douglascrockford/JSLint

Update README
+6 -5

2 comments

1 changed file

jpochetedmead

pr closed time in 5 months

pull request commentdouglascrockford/JSLint

Update README

How is this better?

jpochetedmead

comment created time in 5 months

issue closeddouglascrockford/howjavascriptworks

How to implement type methods (like str.toUpperCase()) in Neo?

Dear Mr. Crockford, Hi, I love your book and Neo as a language prototype. I'm trying to expand Neo into a full-fledged language with static type checking. Neo has most essential features of a language but I can't find a way to add methods to built-in types like text. I'm not familiar with functional programming. However, based on my google search, Clojure implemented type methods using the syntax like clojure.string/upper-case "MiXeD cAsE". So in Neo, should I use something like text.upper("MiXeD cAsE") which is a function method that translates to text("upper", ["MiXeD cAsE"])? Then in the runtime text() function, I will need to handle the specific case where the first argument is a text and the second is a list of texts.

This approach seems possibly ambiguous to me because maybe in the future I want to implement some feature like

// split a text with subtexts listed
text("Start of a sentence, then end it. Another sentence.", [",", "."])
// output: ["Start of a sentence", " then end it", " Another sentence", ""]

which has the same parameter types as text.upper().

What's your recommended implementation of type methods in Neo?

closed time in 5 months

AlienKevin

issue commentdouglascrockford/howjavascriptworks

How to implement type methods (like str.toUpperCase()) in Neo?

I recommend using functions instead of methods. Take a look at Rebol. http://www.rebol.com/

AlienKevin

comment created time in 5 months

push eventdouglascrockford/DEC64

Douglas Crockford

commit sha 3481866fe2da0485fe2012edd08bbd3e0fe2d446

round

view details

Douglas Crockford

commit sha aabc2e4a1c8cb8ecbf06d3605d4778621904c33b

round

view details

Douglas Crockford

commit sha b620a8ad161bf4127b6c99efe4274f9b542ddbcb

whitespace

view details

Douglas Crockford

commit sha 1853206415f6ca0819e8d80ea14c7708bd9659d0

nonnan

view details

Douglas Crockford

commit sha bc0bc8ef7c84b084a05720f6305e6f1f61aa5054

ARM64 Support for ARM 64-bit processors.

view details

push time in 5 months

issue closeddouglascrockford/JSON-js

Json syntax

Im getting lost. The standard at https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf says

value => string //etc object array array => [ values ] object => string : value values => value value, values therefor the following should be valid json:

[ "name" : { 1, 2, 3 }, 1, 2, 3 ]

whereas if i follow your syntax at json.org (the bit on the right) it isn't valid. also most other checkers ive tried say its not valid json.

However the bit on the left follows the standard.

The following follows ecma: "n" : {"name" :"value", "n":1, "k":2 }

however its invalid.

closed time in 5 months

mgwalm

issue commentdouglascrockford/JSON-js

Json syntax

You are misreading ECMA 404. If you are having trouble understanding grammar rules, then try using the railroad diagrams.

mgwalm

comment created time in 5 months

issue closeddouglascrockford/JSON-js

Json syntax

Im trying to understand the json systax. Your page at https://www.crockford.com/mckeeman.html says the following

json element

surely it should be json elements

closed time in 5 months

mgwalm

issue commentdouglascrockford/JSON-js

Json syntax

Surely not.

mgwalm

comment created time in 5 months

push eventdouglascrockford/JSLint

Douglas Crockford

commit sha e1fb05d6ef2fb4d6063e05aadeda97fb68917f7c

/\-/u

view details

push time in 5 months

issue commentdouglascrockford/JSLint

JSLint should warn on \ in /\-/u

Why does that happen?

EvgenyOrekhov

comment created time in 5 months

push eventdouglascrockford/DEC64

Douglas Crockford

commit sha ce0927ff4d28fb737dcae10b23c2f006c05b83d2

obj

view details

push time in 5 months

push eventdouglascrockford/DEC64

Douglas Crockford

commit sha 9e33f96ffec1ac7a9b7955417a3f5e3ae4ae3361

dec64.obj

view details

push time in 5 months

more