//mixin函数

基础使用方法

--包含选择器,example:
.test(){
&:hover{
border:1px solid red;
}
} button{
.test;
} //output css
button:hover {
border: 1px solid red;
} --命名空间,example:
.test(){
.Height{
height:80px;
}
} //grammar 1
.study{
.test>.Height;
} //grammar 2
.study{
.test > .Height;
} //grammer 3
.study{
.test .Height;
} //grammar 4
.study{
.test.Height;
} //output css
.study {
height: 80px;
} 小结:你可以在mixin函数中定义多个函数,并可以用以上4种任意方法去调用,他们之间的空格和>都是可选的
可有的类似于JavaScript中的方法对象,区别在于他的调用没有那么严谨,example:
#outer > .inner;
#outer > .inner();
#outer .inner;
#outer .inner();
#outer.inner;
#outer.inner();
全部都是可以成功调用#outer mixin函数中的.inner函数--(此处来自文档) --保护命名空间,example: @mianColor:red; //grammar 1
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
} //output css
#test .childColor {
border: 1px solid blue;
} //grammar 2
#test when(@mianColor=red){
.childColor(){
border:1px solid blue;
}
.study{
.childColor;
}
} //output css
#test .study {
border: 1px solid blue;
} 当这个时候.childColor函数无论是立即执行还是指定条件执行在#test外部都是无法调用的,这样起到命名空间保护
这里的 when(@mianColor=red)起到了当在指定条件为true是才会执行
注意:@mianColor的声明必须在外部才会起到作用,example:
when true
//grammar 1
@mianColor:red;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
} //grammar 2
@mianColor:blue;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
}
@mianColor:red; when false
//grammar 1
@mianColor:blue;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
} //grammar 2
@mianColor:red;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
}
@mianColor:blue; //error grammar 1
@mianColor:red;
#test when(@mianColor=red){
@mianColor:blue;
.childColor{
border:1px solid blue;
}
}
这样的最终结果还是为真 //error grammar 2
@mianColor:blue;
#test when(@mianColor=red){
@mianColor:red;
.childColor{
border:1px solid blue;
}
}
这样的最终结果还是为假 小结:内部不会改变外部声明变量,同时外部也不能调取内部函数,这其实和JavaScript函数的闭包是一个道理

作者:leona

原文链接:http://www.cnblogs.com/leona-d/p/6296580.html

版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接

Less-mixin函数基础二的更多相关文章

  1. python 18 函数基础二

    转自 http://www.cnblogs.com/BeginMan/p/3173328.html 一.装饰器(decorators) 装饰器的语法以@开头,接着是装饰器函数的名字.可选参数. 紧跟装 ...

  2. 函数基础(二)(day11整理)

    目录 昨日内容 函数的定义 函数的三种定义方式 空函数 有参函数 无参函数 函数的调用 函数的返回值 函数的参数 形参 实参 今日内容 可变长参数 可变长形参 可变长实参(仅作了解) 函数对象 函数嵌 ...

  3. PHP基础入门(二)【PHP函数基础】

    PHP基础入门(二)--函数基础 了解 PHP基础入门详解(一) 后,给大家分享一下PHP的函数基础. 这部分主要讲的就是: 函数的声明与使用.PHP中变量的作用域.静态变量.函数的参数传递.变量函数 ...

  4. LR函数基础(一)(二)

    LR函数基础(一) 函数用到:web_reg_find(). lr_log_message(). lr_eval_string().strcmp().atoi() Action(){    web_r ...

  5. Ruby语法基础(二)

    Ruby语法基础(二) 继续ruby的学习,这次主要把目光放到运算符,条件判断,循环,方法,以及其他ruby特有的基本概念上 运算符 算术运算符:+,-,/,%,**,值的注意的是,ruby中一切皆为 ...

  6. jdbc基础 (二) 通过properties配置文件连接数据库

    csdn博文地址:jdbc基础 (二) 通过properties配置文件连接数据库 上一篇描述了对mysql数据库的简单操作,下面来看一下开发中应该如何灵活应用. 因为jdbc对数据库的驱动加载.连接 ...

  7. Python 函数基础、有序集合、文件操作(三)

    一.set 特点: set是一个无序且不重复的元素集合访问速度快:天生解决元素重复问题 方法: 初始化 >>> s1 = set()>>> print(type(s ...

  8. 【2017-03-05】函数基础、函数四种结构、ref和out参数、递归

    一.函数基础 1.函数/方法:非常抽象独立完成某项功能的一个个体 2.函数的作用: 提高代码的重用性提高功能开发的效率提高程序代码的可维护性 3.分类 固定功能函数高度抽象函数 4.函数四要素:输入, ...

  9. PHP基础入门(三)---PHP函数基础

    PHP基础入门(三)---函数 今天来给大家分享一下PHP的函数基础.有了前两章的了解,想必大家对PHP有了一定的基础了解.想回顾前两章的朋友可以点击"PHP基础入门(一)"&qu ...

随机推荐

  1. JSR 303 - Bean Validation 介绍及最佳实践(转)

    JSR 303 – Bean Validation 是一个数据验证的规范,2009 年 11 月确定最终方案.2009 年 12 月 Java EE 6 发布,Bean Validation 作为一个 ...

  2. 点滴积累【JS】---JS小功能(JS实现模仿微博发布效果)

    效果: 思路: 利用多功能浮动运动框架实现微博效果,首先,将textarea中的属性添加到新创建的li里面然后,再将li添加到ul里面,再利用浮动运动框架将数据动态的显示出来. 代码: <hea ...

  3. c#动态类型

    class Program { static void Main(string[] args) { dynamic test = new ExpandoObject(); test.Name = &q ...

  4. 已安装 SQL Server 2005 Express 工具。若要继续,请删除 SQL Server 2005 Express 工具

    数据库安装sql server2008R2时遇到. 安装sql server 2008 management,提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL Serv ...

  5. 【项目总结】:怎样做一个牛逼的Team leader?

    随着ITOO高校云平台3.1项目的结束,我们各种各样的总结也被提上了日程. Java版本号的全部开发者和Donet版本号的全部开发者坐在一起进行了关于项目开发管理的头脑风暴,尽管我仅仅是Donet开发 ...

  6. 1.Vector(向量容器)

    一.概述 Vectors 包含着一系列连续存储的元素,其行为和数组类似.访问Vector中的任意元素或从末尾添加元素都可以在常量级时间复杂度内完成,而查找特定值的元素所处的位置或是在Vector中插入 ...

  7. poj 3617 Best Cow Line (字符串反转贪心算法)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9284   Accepted: 2826 Des ...

  8. iOS开发多线程篇 07 —GCD的基本使用

    iOS开发多线程篇—GCD的基本使用 一.主队列介绍 主队列:是和主线程相关联的队列,主队列是GCD自带的一种特殊的串行队列,放在主队列中得任务,都会放到主线程中执行. 提示:如果把任务放到主队列中进 ...

  9. gitlab仓库服务器搭建

    ``` curl -sS http://packages.gitlab.cc/install/gitlab-ce/script.rpm.sh | sudo bash sudo yum install ...

  10. bcrypt install `node-pre-gyp install --fallback-to-build`

    npm安装parse-server的过程中遇到了2次错误 尝试1 ganiks@ganiks-ubuntu-trusty-64:~$ sudo npm i -g parse-server npm WA ...