- Goal
Uninvert the inversion of control → instead of handling the continuation of out program to anther party, we could expect it to return us a capability to know when its task finishes, and decide what our code to do next.
- Future Value
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
* { | |
box-sizing: border-box; | |
} |
const getProp = (path, target) => { | |
try { | |
const paths = path.split('.'); | |
const isProp = paths[1] in target; | |
if (paths.length === 2) { | |
return isProp ? target[paths[1]] : undefined; | |
} | |
return isProp ? getProp(paths.slice(1).join('.'), target[paths[1]]) : undefined; | |
} catch (error) { | |
return undefined; |
function do_parseImg () { | |
if ($(this).nextAll('.content-img').length > 0) { return } | |
var url = $(this).text().split('\n').reduce(e => e.trim().match(/^\!\[.*\]\((.+)\)$/)); | |
url && $(this).after('<div class="content-img"><img style="width:85%" src="' + url[1] + '"/></div>'); | |
} | |
function parseImg () { | |
$('div.notes div.content').focusin(function () { | |
$(this).nextAll('.content-img').remove(); | |
}); |