Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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