数学中的链式法则

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()

转载于:https://www.cnblogs.com/lightsong/p/5738649.html

lua OOP实现对象的链式调用相关推荐

  1. javascript --- 对象的方式体验链式调用

    将功能相近的方法写入同一个对象中,是一个很好的编程习惯,便于后期的维护和前期的开发. foo1 var fooObj = {foo1: function() {console.log('foo1'); ...

  2. Lombok链式调用,子类对象set父类属性,返回父类对象

    前言 lombok相信大家都用过,没用过肯定也不会点进来,一直用着都很舒服.今但是天在码代码时,碰到了一个问题,卡了半天.问题是这样的:Lombok链式调用父类中的set属性时,返回的居然是一个父类对 ...

  3. jq的链式调用.end();

    jq的链式调用.end(); 先上code <!DOCTYPE html> <html lang="en"> <head><meta ch ...

  4. [jQuery] jQuery是如何链式调用的?

    [jQuery] jQuery是如何链式调用的? 返回对象本身即可,类似 obj = { func: function(){ return obj } }, 那么 obj.func().func() ...

  5. 实现同步请求_图解 Promise 实现原理(二)—— Promise 链式调用

    摘要 很多同学在学习 Promise 时,知其然却不知其所以然,对其中的用法理解不了.本系列文章由浅入深逐步实现 Promise,并结合流程图.实例以及动画进行演示,达到深刻理解 Promise 用法 ...

  6. 彻底掌握 Promise-原生Promise的实现(二) Promise的链式调用

    在 彻底掌握 Promise- 原生 Promise 的实现(一) 已经初步实现了 promise 的简易版本,这距离实现完整版本的 Promise 还有一段距离,下面我们将在简易版本的基础上增加 P ...

  7. 设计模式之建造者模式(含链式调用)

    开始之前 大家都知道建造者模式是23种设计模式之一,其属于创建型模式,我们可以先看一下菜鸟教程对建造者模式的介绍. 建造者模式(Builder Pattern)使用多个简单的对象一步一步构建成一个复杂 ...

  8. Java8链式调用_java链式调用(转载http://www.cnblogs.com/quiet-snowy-day/p/6091233.html)

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

  9. Android 快速实现新手引导层的库,通过简洁链式调用,一行代码实现引导层的显示

    NewbieGuide 项目地址:huburt-Hu/NewbieGuide  简介:Android 快速实现新手引导层的库,通过简洁链式调用,一行代码实现引导层的显示 更多:作者   提 Bug 标 ...

最新文章

  1. java 常见中文乱码问题解决
  2. 鸿蒙智慧屏电视,鸿蒙os全面推送,立刻买了一台华为智慧屏电视s pro65
  3. RIM发警告 部分黑莓手机存在安全漏洞
  4. Javascript中call的使用
  5. elasticsearch id查询_互联网公司中对【Elasticsearch】的真实应用案例
  6. python struct pack解析_Python struct 详解
  7. java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
  8. 【计算机组成原理】数据存储的大端和小端
  9. 中值滤波器 ( Median Filter ) C++ 实现
  10. Union的一个妙法
  11. 原创 | 职场风云 (二)试验田
  12. SCSI设备IO过程:磁盘上线与IO过程
  13. Tkinter单选框
  14. C语言小熊时钟实验报告,用VC6.0编写一个小熊时钟(求代码)
  15. 数据库中索引原理及填充因子
  16. 电脑C盘满了怎么办?电脑C盘满了怎么清理?
  17. quorum examples初探
  18. Java 在PPT中添加文本水印的简易方法(单一/平铺水印)
  19. excel文件被写保护怎么解除_excel撤销写保护的教程
  20. PaperWork php源码,一个开源记笔记/存档的程序:Paperwork

热门文章

  1. 中小学生应不应该学英语?
  2. 营销、销售和运营的区别?
  3. 给初创业者的几点建议
  4. 未来经济会发展到什么程度?
  5. 为什么有的人手机通知栏显示的是4G+而有的是HD?
  6. Of course, Huawei has brought more than just
  7. 在SQL Server中批量复制,导入和导出的技术
  8. 报告正在使用哪些Reporting Services数据集字段?
  9. sql server 别名_SQL Server别名概述
  10. ssis 映射列 使用变量_SSIS中的动态列映射:SqlBulkCopy类与数据流