Skip to content

Instantly share code, notes, and snippets.

@IPRIT
Created March 6, 2016 00:36
Show Gist options
  • Select an option

  • Save IPRIT/bbae4496f25fd101ffb8 to your computer and use it in GitHub Desktop.

Select an option

Save IPRIT/bbae4496f25fd101ffb8 to your computer and use it in GitHub Desktop.

Задание

Используйте Function#bind для реализации логирующей функции.

Вам необходимо создать функцию, которая будет логировать некоторую информацию с заданным неймспейсом.

Аргументы

  • namespace: строка, которая вставляется в начало сообщения.

Пример

var info = logger('INFO:')
info('this is an info message')
// INFO: this is an info message

var warn = logger('WARN:')
warn('this is a warning message', 'with more info')
// WARN: this is a warning message with more info

Условия

  • Использовать Function#bind

Шаблон

function logger(namespace) {
  // SOLUTION GOES HERE
}

var zeroFill = function (num) { return num < 10 ? '0' + num : num },
	currentTime = new Date(),
	logTime = '[' 
		+ zeroFill(currentTime.getHours()) 
		+ ':' + zeroFill(currentTime.getMinutes()) 
		+ ':' + zeroFill(currentTime.getSeconds())
		+ ']',
	log = logger(logTime);
log('Что-то произошло'); // [18:00:01] Что-то произошло

Ресурсы

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment