diff --git a/bower.json b/bower.json index 6b1426a..f404113 100644 --- a/bower.json +++ b/bower.json @@ -1,9 +1,9 @@ { "name": "enofjs", - "version": "1.1.3", + "version": "1.2.0", "main": "src/enofjs", "devDependencies": { - "jasmine": "2.0.0" + "jasmine": "^2.0" }, "homepage": "http://enof.github.io/EnoFJS/", "authors": [ diff --git a/package.json b/package.json index 2e4eba1..3f1da27 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,37 @@ { "name": "enofjs", "description": "Enhancing javascript", - "version": "1.1.3", + "version": "1.2.0", "dependencies": {}, "devDependencies": { - "grunt": "~0.4.1", - "load-grunt-tasks": "~0.1.0", - "grunt-contrib-jshint": "~0.6.0", - "grunt-contrib-watch": "~0.5.2", - "grunt-contrib-uglify": "~0.2.0", - "time-grunt": "~0.1.0", - "grunt-karma": "~0.6.2", - "karma-script-launcher": "~0.1.0", - "karma-chrome-launcher": "~0.1.0", - "karma-firefox-launcher": "~0.1.0", - "karma-html2js-preprocessor": "~0.1.0", - "karma-requirejs": "~0.1.0", - "karma-jasmine": "~0.1.3", - "karma-coffee-preprocessor": "~0.1.0", - "karma-phantomjs-launcher": "~0.1.0", - "karma": "~0.10.2", - "karma-ng-html2js-preprocessor": "~0.1.0", - "karma-coverage": "~0.1.0", - "grunt-groc": "~0.4.5" + "grunt": "^0.4", + "load-grunt-tasks": "^0.1", + "grunt-contrib-jshint": "^0.6", + "grunt-contrib-watch": "^0.5", + "grunt-contrib-uglify": "^0.2", + "time-grunt": "^0.1", + "grunt-karma": "^0.6", + "karma-script-launcher": "^0.1", + "karma-chrome-launcher": "^0.1", + "karma-firefox-launcher": "^0.1", + "karma-html2js-preprocessor": "^0.1", + "karma-requirejs": "^0.1", + "karma-jasmine": "^0.1", + "karma-coffee-preprocessor": "^0.1", + "karma-phantomjs-launcher": "^0.1", + "karma": "^0.10", + "karma-ng-html2js-preprocessor": "^0.1", + "karma-coverage": "^0.1.0", + "grunt-groc": "^0.4" }, "engines": { "node": ">=0.8.0" }, "scripts": { "test": "grunt test" + }, + "repository": { + "type": "git", + "url": "git@github.com:EnoF/EnoFJS.git" } } diff --git a/src/ClassFactory.js b/src/ClassFactory.js index 9bb6349..a416583 100644 --- a/src/ClassFactory.js +++ b/src/ClassFactory.js @@ -269,6 +269,16 @@ return functionName; }; + // When an innerfunction will be passed down to an other function, it could be that the scope + // will be modified. Think of event handlers. + // Now you can pass the function with `this.private.getFoo.bind(this)`. This will preserve the scope. + Function.prototype.bindScope = function bindScope(scope) { + var self = this; + return function boundScope() { + return self.apply(scope, arguments); + }; + }; + // **Getters, Setters and Issers** // `get || getSet` diff --git a/test/spec/ClassFactorySpec.js b/test/spec/ClassFactorySpec.js index c2545ab..cde9330 100644 --- a/test/spec/ClassFactorySpec.js +++ b/test/spec/ClassFactorySpec.js @@ -366,6 +366,9 @@ this.public = { getFoo: function getFoo() { return this.protected.foo; + }, + reapply: function reapply() { + this.public.getFoo.bindScope(this).apply({}); } }; }); @@ -393,6 +396,13 @@ var child = new Child(); expect(child.getFoo()).toEqual('bar'); }); + + it('should be able to apply with a different scope', function applyDifferentScope() { + var parent = new Parent(); + expect(function testing() { + parent.reapply(); + }).not.toThrow(); + }); }); }); }());