Created
January 25, 2015 19:52
-
-
Save whizark/510101032813eee49bdf to your computer and use it in GitHub Desktop.
Sass: Pseudo `undefined` value to distinguish `null`. #sass
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
// ---- | |
// Sass (v3.4.9) | |
// Compass (v1.0.1) | |
// ---- | |
// Sass: Pseudo `undefined` value to distinguish `null`. | |
// | |
// http://twitter.com/whizark | |
// | |
// Other ideas | |
// https://github.com/whizark/xass#ideas | |
// Function | |
@function undefined() { | |
@if not global-variable-exists('-undefined') { | |
$-undefined: unique-id() !global; | |
} | |
@return $-undefined; | |
} | |
// Use case | |
@function value-of($value: undefined()) { | |
@if $value == undefined() { | |
// do something. | |
@return 'undefined'; | |
} | |
@return $value; | |
} | |
.test | |
{ | |
test: inspect(value-of()); | |
test: inspect(value-of(null)); | |
} |
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
.test { | |
test: "undefined"; | |
test: null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment