This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isNan(value) { | |
| return value !== value; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Number.isNaN = Number.isNaN || (function(value) { | |
| return value !== value; | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isNan(value) { | |
| return Object.is(value, Number.NaN); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Метод #1: свойство constructor | |
| // Ненадежный метод | |
| function isArray(value) { | |
| return typeof value == 'object' && value.constructor === Array; | |
| } | |
| // Метод #2: instanceof | |
| // Ненадежный метод в связи с возможностью изменения прототипа объекта | |
| // Непредвиденные результаты при работе с `iframe` | |
| function isArray(value) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function type(value) { | |
| var regex = /^\[object (\S+?)\]$/; | |
| var matches = Object.prototype.toString.call(value).match(regex) || []; | |
| return (matches[1] || 'undefined').toLowerCase(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log(type('')); // "string" | |
| console.log(type('hello')); // "string" | |
| console.log(type(String('hello'))); // "string" | |
| console.log(type(new String('hello'))); // "string" | |
| console.log(type(0)); // "number" | |
| console.log(type(-0)); // "number" | |
| console.log(type(0xff)); // "number" | |
| console.log(type(-3.142)); // "number" | |
| console.log(type(Infinity)); // "number" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // объект-обертка: new String("Hello World!") | |
| (new String("Hello World!")).toLowerCase(); | |
| // объект-обертка: new String("Another String") | |
| (new String("Another String"))[8]; | |
| // объект-обертка: new Number(53.12345) | |
| (new Number(53.12345)).toFixed(2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { readFile } from "fs"; | |
| router.get("/some-file", function (req, res) { | |
| const url = "./data/some-file.ext"; | |
| readFile(url, function (err, file) { | |
| if (err) { | |
| res.writeHead(404); | |
| res.end(); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function handleError (err) { /* ... */ } | |
| function handleSuccess (x) { /* ... */ } | |
| function nodeCallback (err, thingIWant) { | |
| if (err) { | |
| handleError(err); | |
| } else { | |
| handleSuccess(thingIWant); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| router.get("/some-file", function (req, res) { | |
| const url = "./data/some-file.ext"; | |
| function handleError (err) { | |
| res.writeHead(404); | |
| res.end(); | |
| } | |
| function handleSuccess (file) { | |
| res.writeHead(200, { "Content-Type": "application/octet-stream" }); |