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, ...
随机推荐
- [vuex]——使用vuex解决模块间传值问题
二月的第四个周末,在家.受寒流的影响,深圳天气持续冰冻了好几天,天冷人就变得懒动,迷迷糊糊睡到了快十点,终于在饥饿的催促下起床. 和妹子吃完粥后,百无聊赖.透过窗户,发现太阳依旧没有露头的打算,我们也 ...
- C++设计与声明——让接口容易被正确使用
一个简答易错的例子 class Date { public Date(int month,int day,int year); } 一年后使用这个接口的时候,写了Date d(15,10,2015)或 ...
- sgu 137. Funny Strings 线性同余,数论,构造 难度:3
137. Funny Strings time limit per test: 0.25 sec. memory limit per test: 4096 KB Let's consider a st ...
- Beta阶段第2周/共2周 Scrum立会报告+燃尽图 12
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制:https://git.coding.net/liuyy08 ...
- New Concept English Two 5
$课文9 冷遇 83. On Wednesday evening, we went to the Town Hall. 星期三的晚上,我们去了市政厅. 84. It was the last day ...
- 关于React setState的实现原理(一)
前言 首先在学习react的时候就对setSate的实现有比较浓厚的兴趣,那么对于下边的代码,可以快速回答吗? class Root extends React.Component { constru ...
- ubuntu16.04安装Nvidia显卡驱动、CUDA8.0和cudNN V6
Nvidia显卡驱动安装 在ubuntu搜索框输入 软件更新,打开 "软件和更新" 对话框,在 附加驱动里选择系统检测到的Nvidia驱动,应用更改,重启系统: 安装完成之后查看G ...
- ieee80211 phy1: Failed to select rate control algorithm
/************************************************************************ * ieee80211 phy1: Failed t ...
- supervisor 使用tips
Supervisor (http://supervisord.org) 是一个用 Python 写的进程管理工具,可以很方便的用来启动.重启.关闭进程,supervisor可以同时监控多个进程,并可以 ...
- 0302 IT行业就业与软件工程
阅读以下文章 http://www.thea.cn/news/terminal/9/9389.html http://www.shzhidao.cn/system/2015/09/22/0102610 ...