Minimitter = function Minimitter() {
this.listeners = {};
};
Minimitter.prototype.on = function(name, callback) {
this.listeners[name] = this.listeners[name] || [];
this.listeners[name].push(callback);
};
Minimitter.prototype.off = function(name, callback) {
this.listeners[name] = this.listeners[name] || [];
var indexOfCallback = this.listeners[name].indexOf(callback);
if(~indexOfCallback) {
this.listeners[name].splice(indexOfCallback, 1);
}
};
Minimitter.prototype.emit = function(name, data) {
this.listeners[name].forEach(function(callback) {
try {
callback(data);
} catch(err) {
console.error('A callback has failed.');
}
});
};
var test = Object.create(new Minimitter);
test.on("user", function (name) {
console.log("Username:", name)
})
test.emit("user", "Bob")
console.log("Hello world")
setTimeout(() => console.log("Hello timeout"), 50)
console.log("Hello JS")
console.log("Hello world")
console.log("Hello JS")
console.log("Hello timeout")
export default class Request extends Component {
constructor() {
super();
this.state = {
checked: false
}
this.handleClick = this.handleClick.bind(this);
}
this.handleClick() {
this.setState({
checked: !this.state.checked
})
}
render() {
const {checked} = this.state
return (
<div class="block" onClick={ this.handleClick } role="button" tabIndex={ 0 }>
<input type="radio" name="radio" id="radio" checked={checked}/>
</div>
);
}
}
Array.prototype.asyncEach = function (each, done) {
var i = -1, a = this
function iter() {
if (++i === a.length) { done && done(); return }
each.call(a, a[i], iter)
}
iter()
}
// Example
;(new Array(10)).asyncEach(function (item, next) {
setTimeout(function () {
console.log("tick")
next()
}, 1000)
}, function () {
console.log("done")
})
Array.prototype.asyncEach = function (each, done) {
var i = -1, a = this
function iter() {
if (++i === a.length) { done && done(); return }
each.call(a, a[i], iter)
}
iter()
}
let objectGame = ["GTA", "CS", "OTHER"]
db.connect()
objectGame.asyncEach(function (item, next) {
parserGame(item, getResultOneGame)
next()
}, db.end)
Number(120)
. Т.е это упрощенный вид написания значения.var name = "Leo";
До того как мы создали переменную name
ее не было, но мы ее инициализировали и ее стало.name="fighter_a_1"
name="fighter_a_2"
name="fighter_a_3"