Skip to content

Instantly share code, notes, and snippets.



View GitHub Profile
View gist:70d5ad0b06aa401d4f32

The only reason you are able to call Function.prototype.snapshotFunction as Function.snapshotFunction is because Function is itself a function, as are Object, String, Number, and any other JavaScript "class". If you replaced Function with String, this would no longer work. You added a method to all functions and called it on the function instance Function. So if you tried using this, it would reference the built-in Function function. So yes, this should either be a free-standing function, or, if you wanted to make it a method (e.g. getPrimitive.snapshot(["testPrimitive", testPrimitive])), then remove the first parameter of the function, and replace all references to it in the function with this. Speaking of this, I can't think of all the use cases for your function involving this, but with code like this, it's pretty likely this will cause something to break. I found an example here.

IMO, the [string, value, string, value, ...] thing is bad API de

You can’t perform that action at this time.