Array object's properties and methods

The Array object's properties and methods are described below:

NN: Netscape, IE: Internet Explorer

Properties

Syntax: object.property_name

PropertyDescriptionNNIE 
constructorContains the function that created an object's prototype44
lengthReturns the number of elements in the array34
prototypeAllows you to add properties to an array34

Methods

Syntax: object.method_name()

MethodDescriptionNNIE
concat()Joins two or more arrays and returns a new array44
join(delimiter)Puts all the elements of an array into a string separated by a specified delimiter (comma is default)34
pop()Removes and returns the last element of an array45.5
push("element1","element2")Adds one or more elements to the end of an array and returns the new length45.5
reverse()Reverses the order of the elements in an array34
shift()Removes and returns the first element of an array45.5
slice(begin[,end])Creates a new array from a selected section of an existing array44
sort()Sorts the elements of an array34
splice(index,howmany[,el1,el2])Adds and/or removes elements of an array45.5
toSource()Returns a string that represents the source code of the array4.064
toString()Returns a string that represents the specified array and its elements34
unshift("element1","element2")Adds one or more elements to the beginning of an array and returns the new length45.5
valueOf()Returns the primitive value of an array43
const relationFunctions = { ancestor: { linked(parent) { this.parent = parent; }, unlinked() { this.parent = null; }, }, descendant: { linked(child) { this.children = this.children || []; this.children.push(child); }, unlinked(child) { this.children = (this.children || []).filter((it) => it !== child); }, }, }; function mapKeys(source, target, map) { Object.keys(map).forEach((key) => { if (source[key]) { target[map[key]] = source[key]; } }); } function makeRelation(options, vantOptions, relation) { const { type, name, linked, unlinked, linkChanged } = relation; const { beforeCreate, destroyed } = vantOptions; if (type === 'descendant') { options.created = function () { beforeCreate && beforeCreate.bind(this)(); this.children = this.children || []; }; options.detached = function () { this.children = []; destroyed && destroyed.bind(this)(); }; } options.relations = Object.assign(options.relations || {}, { [`../${name}/index`]: { type, linked(node) { relationFunctions[type].linked.bind(this)(node); linked && linked.bind(this)(node); }, linkChanged(node) { linkChanged && linkChanged.bind(this)(node); }, unlinked(node) { relationFunctions[type].unlinked.bind(this)(node); unlinked && unlinked.bind(this)(node); }, }, }); } function VantComponent(vantOptions = {}) { const options = {}; mapKeys(vantOptions, options, { data: 'data', props: 'properties', mixins: 'behaviors', methods: 'methods', beforeCreate: 'created', created: 'attached', mounted: 'ready', relations: 'relations', destroyed: 'detached', classes: 'externalClasses', }); const { relation } = vantOptions; if (relation) { makeRelation(options, vantOptions, relation); } // add default externalClasses options.externalClasses = options.externalClasses || []; options.externalClasses.push('custom-class'); // add default behaviors options.behaviors = options.behaviors || []; options.behaviors.push(basic); // map field to form-field behavior if (vantOptions.field) { options.behaviors.push('wx://form-field'); } if (options.properties) { Object.keys(options.properties).forEach((name) => { if (Array.isArray(options.properties[name])) { // miniprogram do not allow multi type options.properties[name] = null; } }); } // add default options options.options = { multipleSlots: true, addGlobalClass: true, }; Component(options); } export { VantComponent };
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值