Last active
August 29, 2015 14:11
-
-
Save codyromano/f510fb0d96e1a0f6756a to your computer and use it in GitHub Desktop.
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 strong (obj, propertyName, type, initValue) { | |
var propertyValue, | |
typeErrorMsg = "Property " + propertyName + " must be a " + type; | |
if (initValue !== undefined && typeof initValue !== type) { | |
throw new TypeError(typeErrorMsg); | |
} | |
propertyValue = initValue; | |
Object.defineProperty(obj, propertyName, { | |
get: function () { | |
return propertyValue; | |
}, | |
set: function (newPropValue) { | |
if (typeof newPropValue === type) { | |
propertyValue = newPropValue; | |
} else { | |
throw new TypeError(typeErrorMsg); | |
} | |
} | |
}); | |
} |
Jk, nice! 😄 😊
It's not true that I wear sunblock to go outside. I just don't go outside.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's my buddy putting the Java in JavaScript. Same guy that wears sunblock when he goes outside and brings earplugs to a concert. He is trying to make JavaScript as rigid as he is, people.