数学中的链式法则

http://sx.zxxk.com/ArticleInfo.aspx?InfoID=164649

链式微分法则:

实数运算的链式法则:

对数运算的链式法则:

平行公理的链式法则:

向量运算的链式法则:

JS对象链式调用方法

http://stackoverflow.com/questions/15029309/how-to-write-jquery-chainable-functions-for-local-usinghttp://stackoverflow.com/questions/15029309/how-to-write-jquery-chainable-functions-for-local-using

ar obj = {
test : function(){
alert("Y");
return this;
},
test2 : function(){
alert("2");
return this;
}
}
obj.test().test2(); // And so on since it returns this

lua OOP实现

--

-- Class helper routines

--

-- Instantiates a class

local function _instantiate(class, ...)

local inst = setmetatable({__class=class}, {__index = class})

if inst.__init__ then

inst:__init__(...)

end

return inst

end

--- Create a Class object (Python-style object model).

-- The class object can be instantiated by calling itself.

-- Any class functions or shared parameters can be attached to this object.

-- Attaching a table to the class object makes this table shared between

-- all instances of this class. For object parameters use the __init__ function.

-- Classes can inherit member functions and values from a base class.

-- Class can be instantiated by calling them. All parameters will be passed

-- to the __init__ function of this class - if such a function exists.

-- The __init__ function must be used to set any object parameters that are not shared

-- with other objects of this class. Any return values will be ignored.

-- @param base The base class to inherit from (optional)

-- @return A class object

-- @see instanceof

-- @see clone

function class(base)

-- __parent 属性缓存父类,便于子类索引父类方法

return setmetatable({__parent = base}, {

__call = _instantiate,

__index = base

})

end

--- Test whether the given object is an instance of the given class.

-- @param object Object instance

-- @param class Class object to test against

-- @return Boolean indicating whether the object is an instance

-- @see class

-- @see clone

function instanceof(object, class)

local meta = getmetatable(object)

while meta and meta.__index do

if meta.__index == class then

return true

end

meta = getmetatable(meta.__index)

end

return false

end

local ChainClass = class()

ChainClass.setFlag = function ( self, flag )

self.flag = flag

print("set flag = "..flag)

return self

end

ChainClass.setType = function ( self, type )

self.type = type

print("set type = "..type)

return self

end

ChainClass.printAttrs = function ( self, flag )

for k,v in pairs(self) do

print("name="..k.." value="..tostring(v))

end

return self

end

local chainObj = ChainClass()

chainObj:setFlag(1):setType(2):printAttrs()

lua OOP实现对象的链式调用的更多相关文章

  1. js原生设计模式——2面向对象编程之js原生的链式调用

    技巧点:对象方法中返回当前对象就可以链式调用了,即方法中写return this; <!DOCTYPE html><html lang="en"><h ...

  2. 如何写 JS 的链式调用 ---》JS 设计模式《----方法的链式调用

    1.以$ 函数为例.通常返回一个HTML元素或一个元素集合. 代码如下: function $(){ var elements = []; ;i<arguments.length;i++){ v ...

  3. 【Java】子类的链式调用

    记录最近在项目设计中遇到的一个小问题. 前提:有这样两个POJO类,它们都可以通过链式调用的方式来设置其属性值,其中一个类继承了另一个类. 问题:通过链式调用,子类对象访问父类方法后,如何使返回对象仍 ...

  4. hasOwnProperty 递归 简单回调 链式调用

    1.hasOwnProperty 函数的返回值为Boolean类型.如果对象object具有名称为propertyName的属性,则返回true,否则返回false. function Box(){ ...

  5. Swift2.1 语法指南——可空链式调用

    原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...

  6. JavaScript设计模式——方法的链式调用

    方法的链式调用: (function() { //私有类 function _$ (els) { this.elements = []; for(var i = 0, len = els.length ...

  7. Swift-09-可空链式调用(Optional Chaining)

    我对这个的理解就是:我们有可能会用到其他的属性或者方法,当我们在使用其他的时候,可以使用点语法去访问另一个的属性,这样的使用,就形成了链式访问. 可空链式调用是一种可以请求和调用属性.方法及下表的过程 ...

  8. js实现方法的链式调用

    假如这里有三个方法:person.unmerried();person.process();person.married();在jQuery中通常的写法是:person.unmerried().pro ...

  9. js简单实现链式调用

    链式调用实现原理:对象中的方法执行后返回对象自身即可以实现链式操作.说白了就是每一次调用方法返回的是同一个对象才可以链式调用. js简单实现链式调用demo Object.prototype.show ...

随机推荐

  1. linux 中修改root的密码

    修改root密码 有的时候会出现忘记了root 用户密码的情况,再次我们可以通过进入single(单)用户模式,将root的密码重新设置,然后重启登录即可. 具体流程: 1.先登录root用户(密码已 ...

  2. XML CDATA节点

    术语CDATA指字符数据.CDATA定义为文本块,但识别为标记. 预定义实体的同位素;,密度,并且与放大器;需要打字并且通常难以阅读的标记.在这种情况下,CDATA部分都可以使用.通过使用CDATA节 ...

  3. 李洪强iOS经典面试题130

    绘图与动画 CAAnimation的层级结构 CAPropertyAnimation是CAAnimation的子类,也是个抽象类,要想创建动画对象,应该使用它的两个子类:CABasicAnimatio ...

  4. [LintCode] Restore IP Address 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  5. [CareerCup] 17.5 Game of Master Mind 猜字游戏

    17.5 The Came of Master Mind is played as follows: The computer has four slots, and each slot will c ...

  6. android-时间选择器和日期选择器

    一.实现动态输入日期和时间 * DataPicker(日历选择器) * DataPicker对象以init()方法指定DatePicker初始的年月日及OnDateChangedListener事件 ...

  7. 使用explain查看mysql查询执行计划

    explain语句: 字段解释: type:     all(全表扫描)     ref() possible_keys:     预测使用什么列做为索引 key:     实际使用的key     ...

  8. mvc获取时间戳

    DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(, , )); DateTime dtNow = DateTime.Parse(Date ...

  9. FK JavaScript之:ArcGIS JavaScript添加Graphic,地图界面却不显示

    使用ArcGIS JavaScript,往地图中添加几个Graphic,基本是与官网示例代码一致.绘制的图形一闪而过之后,就没了 核心代码如下: iniToolBar: function () { t ...

  10. c#语句 随堂练习2

    1.方程ax²+bx+c=0是一元二次方程,求根. 2.输入一个年份 ,判断是不是闰年.(能被4整除但不能被100整除的年份是闰年,有的世纪年也是闰年) 3.标准体重:男士体重=身高-100±3:女士 ...