Skip to content

Instantly share code, notes, and snippets.

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmit": true,
@OlehRovenskyi
OlehRovenskyi / function.js
Last active June 26, 2017 19:58
js function
// function
function hello() {
return 'Hello';
}
hello() // hello
hello() // hello
// function with params
@OlehRovenskyi
OlehRovenskyi / this.js
Last active June 26, 2017 20:00
keywoard this
// this
var a = {
name: 'Вася',
getName: function () {
return this.name;
},
getContext: function() {
return this;
}
@OlehRovenskyi
OlehRovenskyi / index.html
Last active June 26, 2017 20:00
events-closure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
form, form p, form div {
margin: 10px;
border: 1px solid blue;
}
@OlehRovenskyi
OlehRovenskyi / event-loop.js
Created June 28, 2017 11:08
event loop examples
function multiply(a, b) {
return a * b;
};
function square(n) {
return multiply(n, n)
};
function printSquare(n) {
var squared = square(n);
@OlehRovenskyi
OlehRovenskyi / index.html
Created June 28, 2017 11:11
dom manipulation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="dom"></div>
<script src="main.js"></script>
// this
// 1. Шаблон вызова функции
var sum = function(a, b) {
console.log(this); // window
return a + b;
}
console.log(sum(1, 2));
// исправим контекст вызова и перейдем к OOP
function Clock() {
this.start = function () {
setInterval(this.render.bind(this), 1000);
}
}
Clock.prototype.getTime = function () {
return new Date();
}
Clock.prototype.render = function () {
console.log(this.getTime().getMinutes() + ":" + this.getTime().getSeconds());
// -------------- XMLHttpRequest --------------
// 1. Создаём новый объект XMLHttpRequest
var xhr = new XMLHttpRequest();
// 2. Конфигурируем его: GET-запрос на URL 'data.json' - синхронная обработка
xhr.open('GET', 'data.json', false);
// 3. Отсылаем запрос
xhr.send();
@OlehRovenskyi
OlehRovenskyi / index.html
Last active July 31, 2017 17:52
jQuery events
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="info">
Size page: <p class="info__size-page"></p>
Date: <p class="info__date"></p>