Last active
January 24, 2017 19:14
-
-
Save YozhEzhi/4801ac15dd87ecc904a4532cdb7ad178 to your computer and use it in GitHub Desktop.
JS function decoration example
This file contains 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
function checkPermissionDecorator(f) { | |
return function() { | |
if (isAdmin()) { | |
return f.apply(this, arguments); | |
} | |
alert( 'Недостаточно прав' ); | |
} | |
} | |
function save() { ... } | |
save = checkPermissionDecorator(save); | |
// save() invocation now checks permission; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment