Eindhoven Developers Meetup
new Date(2016, 0, 26);
this
?
function foo(cb) {
this.a = 'hey';
cb();
}
function bar() {
console.log(this.a);
}
var hi = bar;
hi.a = 'hi';
foo(hi); //hey
function foo(cb) {
this.a = 'hey';
cb();
}
function bar() {
console.log(this.a);
}
var hi = bar;
hi.a = 'hi';
foo(hi.bind(hi)); //hi
function foo(cb) {
this.a = 'hey';
cb.call(this); //<-- wait a minute!
}
function bar() {
console.log(this.a);
}
var hi = bar;
hi.a = 'hi';
foo(hi.bind(hi)); //hi --- pfew!
const Thing = React.createClass({
foo() {
this.bar();
},
bar() {
console.log('Hi');
},
render() { return <button onClick={this.foo} />; },
});
var Thing = {
foo: function() {
this.bar(); //Uncaught TypeError: this.bar is
//not a function
},
bar: function() {
console.log('Hi');
}
};
document.getElementById('something')
.addEventListener('click', Thing.foo);
var Foo = {
a: 'World',
bar: function() {
console.log(this.a);
},
};
var Whoop = {
a: 'Hello',
bar: Foo.bar,
};
Whoop.bar(); //Hello
function Foo() {} //<-- already an instance
Foo.prototype.bar = function() {};
new foo = Foo(); //1. new object
//2. constructor of Foo
//3. delegate to Foo.prototype
//4. call Foo() in new context
var Foo = {
bar: function() {},
};
var foo = Object.create(Foo, {
a: { value: 'hi' }
});
//or
var foo = Object.create(Foo);
foo.a = 'hi';
//index.js
var Obj = require('./obj');
//obj.js
var Obj = {};
module.exports = Obj;
//index.js
import Obj from './obj';
//obj.js
export default {};
//index.js
import * as lib from './obj';
lib.foo();
//or
import { foo, bar } from './obj';
foo();
//obj.js
export function foo() {};
export function bar() {};
setTimeout(function() {
setTimeout(function() {
setTimeout(function() {}, 0);
}, 0);
}, 0);
async.map(['file1','file2'], fs.stat,
function(err, results){
//results is now an array of stats
//for each file
});
async.parallel([
function(){ ... },
function(){ ... }
], callback);
async.series([
function(){ ... },
function(){ ... }
]);