Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2016 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/88a98b04d90b39605f7ec4c7acd58ef4 to your computer and use it in GitHub Desktop.
Save anonymous/88a98b04d90b39605f7ec4c7acd58ef4 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/xafaqe
<!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>
"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