Comparing version 0.1.2 to 0.2.0
15
index.js
@@ -13,4 +13,19 @@ function fieldsInObject(o) { | ||
function bind(fields, object) { | ||
for (var n = 0; n < fields.length; n++) { | ||
(function (n) { | ||
var field = [fields[n]]; | ||
var value = object[field]; | ||
if (typeof value === 'function') { | ||
object[field] = function () { | ||
return value.apply(object, arguments); | ||
}; | ||
} | ||
})(n); | ||
} | ||
} | ||
module.exports = function (dsl) { | ||
var terms = fieldsInObject(dsl); | ||
bind(terms, dsl); | ||
var callArgs = terms.map(function (p) { return 'dsl.' + p; }).join(','); | ||
@@ -17,0 +32,0 @@ |
{ | ||
"name": "language", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "DSLs for the washed masses", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,25 +9,23 @@ # Language | ||
Because magic scope! | ||
Because magic scope! and because no globals! | ||
var language = require('language'); | ||
var position = {x: 0, y: 0}; | ||
var robot = language({ | ||
position: position, | ||
position: {x: 0, y: 0}, | ||
moveLeft: function() { | ||
position.x--; | ||
this.position.x--; | ||
}, | ||
moveRight: function() { | ||
position.x++; | ||
this.position.x++; | ||
}, | ||
moveUp: function() { | ||
position.y--; | ||
this.position.y--; | ||
}, | ||
moveDown: function() { | ||
position.y++; | ||
this.position.y++; | ||
}, | ||
@@ -34,0 +32,0 @@ }); |
12
robot.js
var language = require('./'); | ||
var position = {x: 0, y: 0}; | ||
var robot = language({ | ||
position: position, | ||
position: {x: 0, y: 0}, | ||
moveLeft: function() { | ||
position.x--; | ||
this.position.x--; | ||
}, | ||
moveRight: function() { | ||
position.x++; | ||
this.position.x++; | ||
}, | ||
moveUp: function() { | ||
position.y--; | ||
this.position.y--; | ||
}, | ||
moveDown: function() { | ||
position.y++; | ||
this.position.y++; | ||
}, | ||
@@ -23,0 +21,0 @@ }); |
@@ -28,2 +28,26 @@ var language = require('..'); | ||
}); | ||
it('can call methods on language object, with this', function () { | ||
var simple = language({ | ||
n: 1, | ||
inc: function (amount) { | ||
if (typeof amount === 'undefined') { | ||
amount = 1; | ||
} | ||
this.n += amount; | ||
}, | ||
val: function () { | ||
return this.n; | ||
} | ||
}); | ||
var f = simple(function () { | ||
inc(); | ||
inc(2); | ||
return val(); | ||
}); | ||
f.should.equal(4); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5230
112
46