var time1 = new Date('9.10.2014 8:45')
, time2 = new Date(+time1 + 45 * 6e4); // => Thu Oct 09 2014 09:15:00
function A(){}
var subO = {
f: function(){
return this.that;
}
}
A.prototype = {
get subO(){
var P = Object.create(subO);
P.that = this;
return P;
}
}
var inst = new A;
inst.subO.f() === inst; // true
function A(){
this.subO = {
f: function(){
return this;
}.bind(this)
}
}
var inst = new A;
inst.subO.f() === inst; // true
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';