- Ext JS 3.0 Cookbook
- Jorge Ramon
- 279字
- 2021-04-01 13:43:45
Extending JavaScript objects, the Ext JS way
You can use Ext JS to enhance the native JavaScript classes by making your own functions appear as if they were members of these classes. This recipe uses the Array
class as an example, explaining how to augment its features by adding a function that will allow an array to copy itself into another array.
How to do it...
Adding a new function to the Array
class is shown in the following steps:
- Use Ext JS to add a new function,
copyTo(array, startIndex)
, to theArray
class's prototype:Ext.applyIf(Array.prototype, { copyTo: function(dest, startIndex) { l = this.length; for (var i = 0; i < l; i++) { dest[startIndex + i] = this[i]; } } })
- Create a
source
array and adestination
array in order to test the new function:var source = new Array(); var destination = new Array(); source[0] = '1'; source[1] = '2'; source[2] = '3'; destination[0] = '4'; destination[1] = '5'; destination[2] = '6'; destination[3] = '7'; destination[4] = '8'; destination[5] = '9';
- Verify that the function is available in the
Array
class:
Ext.applyIf(object1, object2)
copies all of the properties of object2
to object1
, if they do not already exist. This effectively allows you to add new functionality to object1
.
推薦閱讀
- Microsoft Forefront UAG 2010 Administrator's Handbook
- MATLAB計(jì)算機(jī)視覺經(jīng)典應(yīng)用
- Expert Cube Development with Microsoft SQL Server 2008 Analysis Services
- AutoCAD 2020中文版從入門到精通(標(biāo)準(zhǔn)版)
- 3ds max & VRay產(chǎn)品造型設(shè)計(jì)經(jīng)典
- 人臉識(shí)別算法與案例分析
- 中文版Photoshop CS6平面設(shè)計(jì)實(shí)用教程(第2版)
- After Effects CC 2019 影視后期特效合成案例教程
- ABAQUS有限元分析從入門到精通(第3版)
- Illustrator 2024從入門到精通
- Photoshop CC平面設(shè)計(jì)教程(微課版)
- 中文版After Effects CC 2018 動(dòng)漫、影視特效后期合成秘技
- Liferay Portal Systems Development
- After Effects 2023實(shí)訓(xùn)教程
- Flash CS6 動(dòng)畫制作實(shí)戰(zhàn)從入門到精通