1

i'm using a wordpress plugin called DW Question and Answer. I have tried to change some behaviour and stumbled upon this odd problem:

var arr = [];
alert(arr['unique']);

this alerts:

function (){
"use strict";
for(var e=[],i=0;i<this.length;i++)-1==t.inArray(this[i],e)&&e.push(this[i]);return e}

Why is the 'unique' key set with that function?

In another test page on the same system (outside wordpress ) the same code alerts 'undefinded' as expected...

I'm curious to knwo how it is possible to set some keys when creating an empty array.

1
  • That's not a key. That's custom Array's method which has been added by the plugin Commented Aug 24, 2014 at 19:00

1 Answer 1

1

That's because there's a plugin that modified the native Arrays prototype to add custom members. That's usually a very bad practice.

Still, here's how it's done:

Array.prototype.someMember = 'test';

[].someMember; //test
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.