sass的类型判定
由于sass的作者是rubyer,因此它的类型与JS有点不一样,但一样可以类推。
@charset "utf-8";//必须设置了这个才能编译有中文的注释 $gray: #333;//颜色
$number: 12;//数字
$boolean: true;
$array:();
$string:"string";
$string2: 'string';
$null:null;
$map: (
aa:1,
bb:2
);
@mixin box-shadow($shadows) {
-moz-box-shadow: $shadows;
-webkit-box-shadow: $shadows;
box-shadow: $shadows;
} .aaa {
content: type-of($gray);
}
.bbb {
content: type-of($number);
}
.ccc{
content: type-of($boolean);
}
.ddd {
content: type-of($array);
}
.eee {
content: type-of($string);
}
.fff {
content: type-of($string2);
}
.ggg {
content: type-of($null);
}
.hhh {
content: type-of(type-of);
}
.iii {
content: type-of($map);
}
.kkk {
content: type-of(box-shadow);
}
//--------------------------------------
.aaa {
content: color; } .bbb {
content: number; } .ccc {
content: bool; } .ddd {
content: list; } .eee {
content: string; } .fff {
content: string; } .ggg {
content: null; } .hhh {
content: string; } .iii {
content: map; } .kkk {
content: string; }
可以看到sass的类型有null, string, bool, number, list, map, color这几种类型,如果直接拿内置函数的名字或@mixin函数放进type-of里,都是得到字符串。
但type-of不能判定@function函数与@mixin函数,这时就需要用到function_exists, mixin_exists这两个方法了,但我觉得它们的名字起得不好,不是中杠线连在一起!
@charset "utf-8";//必须设置了这个才能编译有中文的注释
@mixin box-shadow($shadows) {
-moz-box-shadow: $shadows;
-webkit-box-shadow: $shadows;
box-shadow: $shadows;
}
.testvar1{
content: function_exists("type-of");
}
.testvar2{
content: mixin_exists("box-shadow");
}
//--------------------------------------
.testvar1 {
content: true; }
.testvar2 {
content: true; }
有了类型判定,我们就可以玩参数泛型化了。
sass的类型判定的更多相关文章
- 深入JavaScript类型判定
JavaScript的数据类型 基本区分方法 ECMAScript标准定义了7种数据类型 6 种 基本类型: Boolean,两种取值:true和false Null,一种取值:null Undefi ...
- 集合的最大缺点是无法进行类型判定(这个缺点在JAVA1.5中已经解决),这样就可能出现因为类型不同而出现类型错误。
集合的最大缺点是无法进行类型判定(这个缺点在JAVA1.5中已经解决),这样就可能出现因为类型不同而出现类型错误. 解决的方法是添加类型的判断. LinkedList接口(在代码的使用过程中 ...
- JS类型判定方法(不包括自定义类型)
//判定数据类型 function isType(obj, type) { return toString.call(obj).indexOf('[object ' + type) == 0; } / ...
- ThinkPHP第五天(提交类型判定常量IS_POST等,错误页面种类,Model实例化方式,模板中使用函数,foreach循环,模板中.语法配置)
1.IS_GET.IS_POST.IS_PUT.IS_DELETE.IS_AJAX常量,方便快捷实现各个判断. 在Action类中还可以使用$this->isPost()等进行判断. 2.错误页 ...
- sass那些事儿
Sass,Syntactically Awesome StyleSheets,语法样式表.Sass有两种实现,ruby-sass与lib-sass,前者用ruby实现,后者用C/C++实现. 一.Sa ...
- JS框架设计之对象类型判断一种子模块
Javascript有两套数据类型,一套是基础数据类型,一套是对象数据类型.基础数据类型包括5种基本数据类型,分别是null,bool,undefined,number,string,也叫简单数据类型 ...
- 如何为WebStorm设置SASS的File Watchers?
Webstorm是一个很牛叉的IDE,现在工作每天都是用它了. 最近开始用SASS,LESS等来写CSS,而在Webstorm中,它自带一个File Watchers功能,设置一下,即可实时编译SAS ...
- 深入浅出TypeScript(4)- 使用接口和类型别名
在TypeScript中,为了可以约束对象定义,提供了两个新的特性,接口和类型别名. TypeScript中的接口 在强类型语言中,都有接口的概念,那么TypeScript中的接口是如何使用的呢? 接 ...
- C# 泛型中的数据类型判定与转换
提到类型转换,首先要明确C#中的数据类型,主要分为值类型和引用类型: 1.常用的值类型有:(struct) 整型家族:int,byte,char,short,long等等一系列 浮点家族:float, ...
随机推荐
- 《免费前端教程不会告诉你这些》知乎LIVE读后感
这个是昨天偶然间在知乎上看到的一个知乎LIVE,答题就是音频在线直播吧,我试听了一下觉得分享的还不错,就买了完整的.主讲人叫方应杭,貌似是个挺牛逼的程序猿,之前没有听过,但这是个典型的科班出生的程序员 ...
- 004——php字符串中处理函数(三)
<?php /** * 字符串替换函数: * str_replace(); 替换字符串或数组元素,区分大小写,第四个参数可选,用于统计替换次数 * str_ireplace()不区分大小写替换 ...
- layers框架
- Qt flash_eraseall nandwrite 进度条显示擦除、烧录
/***************************************************************************** * Qt flash_eraseall n ...
- 【maven】Maven打包后为何文件大小改变了
项目中使用了X.509证书,用Maven打包后,测试时报错: java.security.cert.CertificateException: Could not parse certificate: ...
- js中caller和callee属性详解
一.caller属性返回一个对函数的引用,该函数调用了当前函数.functionName.callerfunctionName 对象是所执行函数的名称.说明对于函数来说,caller 属性只有在函数执 ...
- popup控件代码示例
1.jsp页面input框中的代码 <td class="value"> <input name="demos[0].id" type=&qu ...
- Python VIL Realse
#!/usr/bin/python #-*- coding:utf-8 –*- import os import sys import re import shutil import xlrd imp ...
- php代码编译的实现
1.php是解析型的高级语言,zend内核使用c语言实现,有main函数,php脚本就是输入,内核处理后输出结果,内核将php脚本翻译成c程序可识别的opcode就是php的编译. c语言的编译将c代 ...
- (转)SqlServer为大数据量表建索引
本文转载自:http://blog.csdn.net/iangujun/article/details/8136764 之前从没有用SqlServer数据库处理过大数据量的表,都是用Oracle,然后 ...