This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
works if generator is not calling another function ? | |
example from http://davidwalsh.name/es6-generators-dive | |
similar example at https://gist.github.com/deepak/9a7337d7a641f8af9c8b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getStockPrice() { | |
seq.throw('oops! could not get stock price'); | |
// seq.next(80); | |
} | |
function executeTrade() { | |
setTimeout(function() { | |
console.log("trade done"); | |
seq.next(true); | |
}, 300); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flag = false; | |
var promise = Promise.resolve(); | |
// not linear execution of code! | |
// is the then callback pushed onto the call-stack. how ? | |
promise.then( (x) => { | |
console.log(`flag is ${flag}`); // flag is true | |
}) | |
flag = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pr1 = new Promise( (resolve, reject) => { | |
resolve(1); | |
}); | |
// ignored value. | |
// would have been nice of function is required to have correct arguments | |
// TODO: try with JSHint | |
pr1.then( () => { | |
console.log("hello"); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s = new Set([1,2,3]); | |
s.add("foo"); | |
console.log(s.size); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// output | |
10 | |
// generated code | |
"use strict"; | |
var numbers = regeneratorRuntime.mark(function callee$0$0(start, end) { | |
var i; | |
return regeneratorRuntime.wrap(function callee$0$0$(context$1$0) { | |
while (1) switch (context$1$0.prev = context$1$0.next) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//output | |
repl: Line 30: Direct super call is illegal in non-constructor, use super.doWork() instead | |
28 | | |
29 | doWork() { | |
> 30 | let person = super(); | |
| ^ | |
31 | return `${person} paid`; | |
32 | } | |
33 | } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.7.1 | |
(function() { | |
var Employee; | |
Employee = (function() { | |
function Employee() {} | |
Employee.prototype.doWork = function() { | |
return console.log("done"); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
attr_accessor :params | |
def initialize(params) | |
@params = params | |
end | |
def process(params) | |
puts "====> before: #{params.inspect}" | |
params.merge!(local: "modifications") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.around(:each) do |example| | |
# disabled by design | |
# example.call | |
end | |
end | |
__END__ | |
if i have the above rspec config in `spec_helper.rb` and i run a test |