Javascript 练习

在Array()构造器以及相关的数组文本标识法都不存在的情况下,自定义一个类似的MyArray()构造器,并令其通过以下测试:

var a = new MyArray(1,2,3,"test");
a.toString();
//"1,2,3,test"

a.length;
//4

a[a.length-1];
//"test"

a.push("boo");
//5

a.toString();
//"1,2,3,test,boo"

a.pop();
//boo

a.toString();
//"1,2,3,test"

a.join(",");
//"1,2,3,test"

a.join(" isn\'t");
//1 isn't 2 isn't 3 isn't test"
function MyArray() {
    this.length = arguments.length;

    for (var i=0; i

你可能感兴趣的:(Javascript 练习)