AJAX 学习笔记--patter

1.) DoSomethingLocal is defined as $.fn.DoSomethingLocal. You can add as many custom functions to the jQuery.fn (or simply $.fn) object as required by your plugin implementation. Any function you add to the $.fn object is assumed to work on references to an instance of an element/object that was selected. This is what the $.fn syntax means - we are simply adding a custom interface to a jQuery object that assumes selected elements. 2.) DoSomethingGlobal is applied directly to the global jQuery object as $.DoSomethingGlobal. A function attached to the jQuery framework in such way assumes that it will not work on selected elements but rather it will work in the global scope and contain practically any implementation.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Filter pattern 是一种设计模式,它用于过滤一组对象,只留下符合条件的对象,例如在一个列表中过滤出满足某种条件的元素。该模式通常使用一个过滤器对象来实现过滤操作。 在 Python 中,我们可以使用 filter 内置函数来实现 Filter pattern。filter 函数接受两个参数:一个函数和一个可迭代对象。该函数用于判断可迭代对象中的每个元素是否符合条件,符合条件的元素将被保留下来,最终返回一个新的迭代器,其中只包含符合条件的元素。 下面是一个示例代码,演示了如何使用 filter 函数过滤出所有的偶数: ```python # 定义一个函数,用于判断一个数是否为偶数 def is_even(num): return num % 2 == 0 # 定义一个列表 my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # 使用 filter 函数过滤出所有的偶数 even_numbers = filter(is_even, my_list) # 输出过滤结果 print(list(even_numbers)) # [2, 4, 6, 8, 10] ``` 在上面的示例代码中,我们首先定义了一个名为 `is_even` 的函数,用于判断一个数是否为偶数。然后定义了一个列表 `my_list`,其中包含了一些整数。接着使用 filter 函数过滤出所有的偶数,并将其转换为列表,最终输出过滤结果。 需要注意的是,filter 函数返回的是一个迭代器,如果需要多次遍历符合条件的元素,需要将其转换为列表。例如:`even_numbers = list(filter(is_even, my_list))`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值