数学中的链式法则

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. CentOS 6.4 查看每个进程的网络流量

    所需工具nethogs 安装:yum install -y nethogs 使用:nethogs eth0

  2. Yahoo!网站性能最佳体验的34条黄金守则

    Yahoo!的Exceptional Performance团队为改善Web性能带来最佳实践.他们为此进行了一系列的实验.开发了各种工具.写了大量的文章和博客并在各种会议上参与探讨.最佳实践的核心就是 ...

  3. SolrCloud-如何在.NET程序中使用

    https://github.com/vladen/SolrNet 原来我们在我们的项目里用的是根据数据库路由到不同的单机Solr服务器,但是这样的话,每次Solr配置的修改都要修改三台不通的服务器, ...

  4. Node.js的DES加解密和MD5加密

    最基本的就是经常用的md5加密算法 代码如下 var  MD5=function (data) {        var _encrymd5 = require('crypto').createHas ...

  5. jquery-uploadify 上传

    先从官网下载插件 http://www.uploadify.com/ 引入之后.... html.................... <!-- 上传 --> <div id=&q ...

  6. js从身份证号中获取出生日期和性别

    今天,在做移动端的项目中,按照设计稿的要求,是可以让用户自己输入出生日期的,我还很认真的用了刚刚知道的html5表单的日期类型,本想着终于不用日期插件就可以实现用户选择自己的出生日期了,可结果老大说, ...

  7. 怎么控制表单placeholder属性的样式兼容各大浏览器?

    当我们使用placeholder的时候会遇到样式的控制和版本的兼容问题(但是还是只有css3支持),以至于达不到我们想要的效果,下面来看一种: 下面是css: .invalid:-moz-placeh ...

  8. C程序编译过程

    1.1程序被其他程序翻译成不同的格式 1.hello.c #include <stdio.h> int main() { printf("hello world\n") ...

  9. thinkphp自定义分页效果

    TP自带了一个分页函数,挺方便使用的. 下面是我的使用方法: /*****************分页显示start*************************/ $arr_page=$this ...

  10. unity3d插件Daikon Forge GUI 中文教程1-Daikon Forge介绍

    DF-GUI特点: ·        深编辑器集成:DF-GUI提供广泛的整合与Unity3D编辑环境,包括自定义检查人员对每个组件向导来简化复杂的多步任务,提高生产力的上下文菜单,编辑控件在一个所见 ...