Skip to content

Instantly share code, notes, and snippets.

@whizark
Created January 25, 2015 19:52
Show Gist options
  • Save whizark/510101032813eee49bdf to your computer and use it in GitHub Desktop.
Save whizark/510101032813eee49bdf to your computer and use it in GitHub Desktop.
Sass: Pseudo `undefined` value to distinguish `null`. #sass
// ----
// 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));
}
.test {
test: "undefined";
test: null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment