function escapeRegExp(it){
return String(it).replace(/([\\\-[\]{}()*+?.,^$|])/g, '\\$1');
}
function checkMatch(request, item) {
var _regex = new RegExp('^' + escapeRegExp(request), 'i');
return _regex.test(item);
}
console.log(checkMatch('v.y', 'vry')); // => false
console.log(checkMatch('vry', 'vryzzz')); // => true
.data(nodes, (function (d) {...}).bind(this))
Object.getPrototypeOf(err) === object.exceptions.IncorrectLink.prototype
object.exceptions[key].prototype = Object.create(Error.prototype);
http = require 'http'
module.exports = class Request
get: (url) ->
new Promise (resolve, reject)->
req = http.get url, (res) ->
body = ''
res.on 'data', (chunk) ->
body += chunk.toString()
res.on 'end', ->
resolve body
req.on 'error', reject
require(ваш_модуль).get(ваш_url)
.then (страница)->
.catch (ошибка)->
Function.prototype.part = function(){
var fn = this
, args = [].slice.call(arguments);
return function(){
return fn.apply(this, args.concat([].slice.call(arguments)));
}
}
var lastCall = 0;
function handle() {
var now = Date.now();
if(now - lastCall > 1e3){
// логика ...
lastCall = now;
}
}
window.Function = (function(Function){
return function(){
var fn = Function.apply(window, arguments);
return function(){
console.log('run');
return fn.apply(this, arguments);
}
}
})(Function);
Function('console.log(1)')() // => run 1
function Class(){}
Class.name // => 'Class'
function getName(it){
var match = /^\s*function\s+(\b\w+\b)/.exec(it);
if(match)return match[1];
}
getName(Class) // => 'Class''
function Class(){}
Class.displayName = 'Class';
var type = new Audio().canPlayType('audio/mpeg') ? 'mp3' : 'ogg';
new Audio('audio.' + type).play();
var d1 = Date.now()
, d2 = Date.parse("Wed, 09 Aug 1995 00:00:00")
, interval = new Date(d1 - d2);
// год.месяц.день.час.минута.секунда
console.log([
interval.getUTCFullYear() - 1970,
interval.getUTCMonth(),
interval.getUTCDate() - 1,
interval.getUTCHours(),
interval.getUTCMinutes(),
interval.getUTCSeconds(),
].join('.')); // => 18.7.19.21.30.9
var string = '1234';
string.match(/(\d\d)/g).reverse(); // => ["34", "12"]