-
-
Save aliaspooryorik/6c9930e09828ad7c1d3f73867883a586 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/xafaqe
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
"use strict"; | |
function filter($) { | |
var things = {}; | |
function append(type, terms) { | |
$.each(terms, function(ndx, term) { | |
var emphasis = function() { | |
return term + "!"; | |
} | |
if (!things.hasOwnProperty(type)) { | |
things[type] = []; | |
} | |
var definition = { | |
term: term, | |
question: function() { | |
return term + "?"; | |
}, | |
emphasis: emphasis, | |
memento: function() { | |
return {term: term, emphasis: emphasis()}; | |
} | |
}; | |
things[type].push(definition); | |
}); | |
} | |
function getThings(type) { | |
return things[type]; | |
} | |
return { | |
"append": append, | |
"getThings": getThings | |
}; | |
} | |
var container = filter(jQuery); | |
container.append("not", ["no", "nay"]); | |
container.append("yes", ["yay", "yup", "yip"]); | |
console.clear(); | |
var things = container.getThings("not"); | |
$.each(things, function(ndx, thing) { | |
console.log(ndx, thing.term, thing.question(), thing.emphasis(), thing.memento()); | |
}); | |
var things = container.getThings("yes"); | |
$.each(things, function(ndx, thing) { | |
console.log(ndx, thing.term, thing.question(), thing.emphasis(), thing.memento()); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">"use strict"; | |
function filter($) { | |
var things = {}; | |
function append(type, terms) { | |
$.each(terms, function(ndx, term) { | |
var emphasis = function() { | |
return term + "!"; | |
} | |
if (!things.hasOwnProperty(type)) { | |
things[type] = []; | |
} | |
var definition = { | |
term: term, | |
question: function() { | |
return term + "?"; | |
}, | |
emphasis: emphasis, | |
memento: function() { | |
return {term: term, emphasis: emphasis()}; | |
} | |
}; | |
things[type].push(definition); | |
}); | |
} | |
function getThings(type) { | |
return things[type]; | |
} | |
return { | |
"append": append, | |
"getThings": getThings | |
}; | |
} | |
var container = filter(jQuery); | |
container.append("not", ["no", "nay"]); | |
container.append("yes", ["yay", "yup", "yip"]); | |
console.clear(); | |
var things = container.getThings("not"); | |
$.each(things, function(ndx, thing) { | |
console.log(ndx, thing.term, thing.question(), thing.emphasis(), thing.memento()); | |
}); | |
var things = container.getThings("yes"); | |
$.each(things, function(ndx, thing) { | |
console.log(ndx, thing.term, thing.question(), thing.emphasis(), thing.memento()); | |
}); | |
</script></body> | |
</html> |
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
"use strict"; | |
function filter($) { | |
var things = {}; | |
function append(type, terms) { | |
$.each(terms, function(ndx, term) { | |
var emphasis = function() { | |
return term + "!"; | |
} | |
if (!things.hasOwnProperty(type)) { | |
things[type] = []; | |
} | |
var definition = { | |
term: term, | |
question: function() { | |
return term + "?"; | |
}, | |
emphasis: emphasis, | |
memento: function() { | |
return {term: term, emphasis: emphasis()}; | |
} | |
}; | |
things[type].push(definition); | |
}); | |
} | |
function getThings(type) { | |
return things[type]; | |
} | |
return { | |
"append": append, | |
"getThings": getThings | |
}; | |
} | |
var container = filter(jQuery); | |
container.append("not", ["no", "nay"]); | |
container.append("yes", ["yay", "yup", "yip"]); | |
console.clear(); | |
var things = container.getThings("not"); | |
$.each(things, function(ndx, thing) { | |
console.log(ndx, thing.term, thing.question(), thing.emphasis(), thing.memento()); | |
}); | |
var things = container.getThings("yes"); | |
$.each(things, function(ndx, thing) { | |
console.log(ndx, thing.term, thing.question(), thing.emphasis(), thing.memento()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment