jQuery.sub()返回类型:jQueryversion deprecated: 1.7, removed: 1.9
描述:创建一个jQuery的新副本,可以修改其属性和方法,而不会影响原始的jQuery对象。
-
增补版本:1.5jQuery.sub()
- 此方法不接受任何参数。
此方法在jQuery 1.7中被淘汰了,在jQuery 1.8中被移到一个插件中。
There are two specific use cases for which jQuery.sub() was created. The first was for providing a painless way of overriding jQuery methods without completely destroying the original methods and another was for helping to do encapsulation and basic namespacing for jQuery plugins.
Note that jQuery.sub() doesn't attempt to do any sort of isolation - that's not its intention. All the methods on the sub'd version of jQuery will still point to the original jQuery (events bound and triggered will still be through the main jQuery, data will be bound to elements through the main jQuery, Ajax queries and events will run through the main jQuery, etc.).
Note that if you're looking to use this for plugin development you should first strongly consider using something like the jQuery UI widget factory which manages both state and plugin sub-methods. Some examples of using the jQuery UI widget factory to build a plugin.
The particular use cases of this method can be best described through some examples.
示例:
对jQuery sub添加一个方法,从而它不会外部曝露:
1
2
3
4
5
6
7
8
9
10
11
12
|
|
覆盖一些jQuery方法以提供新功能:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
|
创建一个插件,返回插件特有的方法。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
|