- 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
.
推薦閱讀
- AI繪畫教程:Midjourney使用方法與技巧從入門到精通
- 創(chuàng)意UI:Photoshop玩轉(zhuǎn)移動UI設(shè)計
- Word-Excel-PowerPoint 2010三合一從新手到高手(超值版)
- Software Testing using Visual Studio 2010
- Blender 3D 2.49 Architecture, Buidlings, and Scenery
- Learning Ext JS 3.2
- 中文版Illustrator CC基礎(chǔ)培訓(xùn)教程(移動學(xué)習(xí)版)
- Procreate+ SketchUp +Photoshop建筑設(shè)計手繪表現(xiàn)技法
- Salesforce CRM: The Definitive Admin Handbook
- Photoshop CS6實戰(zhàn)從入門到精通(超值版)
- 新印象:CINEMA 4D電商設(shè)計基礎(chǔ)與實戰(zhàn)(全視頻微課版)
- 中文版3ds Max/VRay效果圖制作完全自學(xué)教程(實例培訓(xùn)教材版)
- Photoshop CS6圖像處理立體化教程
- CorelDRAW 2018平面設(shè)計基礎(chǔ)教程(第3版)
- Apache Solr High Performance