Valid template expressions:
- expressions can reference any property on the passed in context, including nested properties and indexed access to array properties.
{{ name }}
{{ obj.name }}
| let isFunction = function(obj) { | |
| return typeof obj == 'function' || false; | |
| }; | |
| class EventEmitter { | |
| constructor() { | |
| this.listeners = new Map(); | |
| } | |
| addListener(label, callback) { | |
| this.listeners.has(label) || this.listeners.set(label, []); |
| ['Function','Array'].forEach(function(type) { | |
| var checkFn = 'is'+type; | |
| window[checkFn] = function(o){ return Object.prototype.toString.call(o) == '[object ' + type + ']'; }; | |
| }); | |
| // Return new list as combination of the two lists passed | |
| // The second list can be a function which will be passed each item | |
| // from the first list and should return an array to permute that item | |
| // with. If either argument is not a list, it will be treated as a list. | |
| // |
| // | |
| // This is the actual implementation using our minimal functional library | |
| // | |
| var validate = { | |
| 'values': function(o) { return !isNull(o) && !isUndefined(o) && (isBoolean(o) || isNumber(o) || isString(o)); }, | |
| 'arrays': function(o) { return !isNull(o) && !isUndefined(o) && isArray(o); } | |
| } | |
| var build = { | |
| 'values': function(prop, val) { return [prop,"=",qs(val.toString())].join(''); }, |
| /** | |
| * Primary application logic for our Functional Programming blog example | |
| * See related blog series at: http://www.datchley.name/tag/functional-programming/ | |
| * Version: 2.0 | |
| */ | |
| // A simple, resuable comparison for '>=' | |
| function greaterThanOrEqual(a, b) { | |
| return a >= b | |
| } |
| // | |
| // Some common utility combinators and helpers | |
| // | |
| function flip(fn) { | |
| return function() { | |
| var args = [].slice.call(arguments); | |
| return fn.apply(this, args.reverse()); | |
| }; | |
| } |
| var assert = { | |
| test: 1, | |
| equal: function(exp, target) { | |
| console.log("[test](%d) expected "+target+" got " + exp + " (%s)", this.test++, (exp == target ? 'SUCCESS' : 'FAIL')); | |
| } | |
| }; | |
| // SKITTLES | |
| // Given a target goal in kilograms, and a number of | |
| // small bags of skittles (1kg) and large bags of skittles (5kg) |
| <!DOCTYPE html> | |
| <html ng-app="app"> | |
| <head> | |
| <script src="http://code.jquery.com/jquery.min.js"></script> | |
| <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> | |
| <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
| <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> | |
| <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> | |
| <meta charset="utf-8"> | |
| <title>JS Bin</title> |
| <!DOCTYPE html> | |
| <html ng-app="app"> | |
| <head> | |
| <script src="http://code.jquery.com/jquery.min.js"></script> | |
| <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> | |
| <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
| <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> | |
| <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> | |
| <meta charset="utf-8"> | |
| <title>JS Bin</title> |
| var slice = Array.prototype.slice, | |
| join = Array.prototype.join, | |
| concat = Array.prototype.concat, | |
| toString = Object.prototype.toString, | |
| isString = function(o){ return toString.call(o) == '[object String]'; }, | |
| isArray = function(o) { return toString.call(o) == '[object Array]'; }; | |
| // I Combinator |