Last active
September 30, 2016 07:37
-
-
Save SergeyNarozhny/cbe55dc4f7ec2441d1be to your computer and use it in GitHub Desktop.
Native js function carrying realizations
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
//#1 | |
var attitude = function(original, replacement, source) | |
{ | |
return function (source) | |
{ | |
return source.replace(original, replacement); | |
} | |
} | |
var slimify = attitude(/big test mark/ig, "smallone"); | |
var happify = attitude(/sad/ig, "happy"); | |
slimify("Big test mark is used"); // smallone is used | |
happify("Sadman is your Sandman"); //happyman is your Sandman | |
//#2 | |
var param = "someVar"; | |
var attitude = (function(i){ | |
if (i == "someVar") | |
{ | |
return function slimify(str) | |
{ | |
return str.replace(/big test mark/ig, "smallone"); | |
} | |
} | |
else | |
{ | |
return function happify(str) | |
{ | |
return str.replace(/sad/ig, "happy"); | |
} | |
} | |
}(param)); | |
attitude("Big test mark is used"); //smallone is used |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment