Skip to content

Instantly share code, notes, and snippets.

@minimal-scouser
Last active February 10, 2022 04:21
Show Gist options
  • Save minimal-scouser/904448dfde92c91345e583306df68666 to your computer and use it in GitHub Desktop.
Save minimal-scouser/904448dfde92c91345e583306df68666 to your computer and use it in GitHub Desktop.
A way of accessing objects from functions.
// 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