//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. python selenium ---键盘事件

    转自:http://www.cnblogs.com/fnng/p/3258946.html 本节重点: l 键盘按键用法 l 键盘组合键用法 l send_keys() 输入中文运行报错问题 键盘按键 ...

  2. weblogic stuck实验2014-11-14

         以往对weblogic stuck认识是: 1.会造成系统总体慢. 2.在weblogic console中线程监控中会有显示. 3.weblogic使用队列处理线程.隔一段时间会扫描线程队 ...

  3. Django Ajax提交数据请求

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. Current thread must be set to single thread apartment (STA) mode before OLE,当前线程不在单线程单元中,因此无法实例化 ActiveX 控件“8856f961-340a-11d0-a96b-00c04fd705a2”。

    Add the STAThreadAttribute attribute on the Main method. This attribute is required if your program ...

  5. C++语言基础(20)-模板的非类型参数

    一.在函数模板中使用非类型参数 #include <iostream> using namespace std; template<class T> void Swap(T & ...

  6. numpy.ravel()/numpy.flatten()/numpy.squeeze()

    numpy.ravel(a, order='C') Return a flattened array numpy.chararray.flatten(order='C') Return a copy ...

  7. centos6.x 抓取ssh登录的用户名和密码

    systemtap是一款非常强大内核调试工具,可以debug很多关于kernel层的问题.Linux是通过PAM模块检测用户信息和认证信息的,从而确定一个用户是否可以登录系统,利用这个知识点,使用sy ...

  8. poj Squares n个点,共能组成多少个正方形 二分 + 哈希

    题目链接:http://poj.org/problem?id=2002 测试数据: 41 00 11 10 090 01 02 00 21 22 20 11 12 14-2 53 70 05 20 有 ...

  9. js 阻止事件冒泡 支持所有主流浏览器

    function getEvent(){ if(window.event) {return window.event;} func=getEvent.caller; while(func!=null) ...

  10. hdu6069 Counting Divisors 晒区间素数

    /** 题目:hdu6069 Counting Divisors 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意:求[l,r]内所有数的k次方 ...