safer-function
v0.1.2
Published
Function traps for bind, call, and apply.
Downloads
12
Maintainers
Readme
safer-function
Function traps for bind
, call
, and apply
.
Please ensure this module, or any dependent of it, is included before any other or, at least, before any polyfill, to grant reliability.
import {bind, call, apply} from 'safer-function';
const {bind, call, apply} = require('./');
// basic usage
const {toString} = {};
call(toString, 'any object');
const {fromCharCode} = String;
call(fromCharCode, String, 104, 101, 108, 108, 111);
apply(fromCharCode, String, [104, 101, 108, 108, 111]);
// secured bound usage
const fromCharsCall = bind(fromCharCode, String);
fromCharsCall(104, 101, 108, 108, 111);
const fromCharsApply = bind(apply, call, fromCharCode, String);
fromCharsApply([104, 101, 108, 108, 111]);