Last active
February 10, 2022 04:21
-
-
Save minimal-scouser/904448dfde92c91345e583306df68666 to your computer and use it in GitHub Desktop.
A way of accessing objects from functions.
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
| // So I realised this was just a candidate fn. Nothing novel about it. | |
| (function () { | |
| 'use strict'; | |
| var res = { data: [] }; | |
| function check(obj: Object, fn: Function) { | |
| return fn.call(obj) | |
| } | |
| function hasNoData() { | |
| return this.data.length === 0; | |
| } | |
| if ( hasNoData(res) ) { ... do smth } // this is when hasNoData accepts an arg | |
| if ( check(res, hasNoData) ) { ... do smth } // true | |
| }()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment