2019独角兽企业重金招聘Python工程师标准>>>
Array中的lenght不仅仅是表示一个变量的读取 还可以直接设置
array.lenght = 3;即把当前的数组个数设置为3 如果原先少于3个则补undefined 如果原先大于3个则直接丢掉 再去访问丢掉的位置 也是返回undefined WTF!!
代码
var test = {array_lenght:function(){var array = ['a','b','c','d'];console.log('before:'+array[3]);array.length=3;console.log('after:'+array[3]);},arraty_lenght2:function(){var array = ['a','b','c','d'];console.log('before:'+array[4]);array.length=5;console.log('after:'+array[4]);}};
测试用例
TestTest = TestCase("TestTest");
TestTest.prototype.testArrayLenght = function(){test.array_lenght();test.arraty_lenght2();assertTrue(true);
};
输出
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -cp /Applications/WebStorm.app/plugins/JsTestDriver/lib/JsTestDriver-plugin-rt.jar:/Applications/WebStorm.app/plugins/JsTestDriver/lib/JsTestDriver-1.3.5-patched.jar:/Applications/WebStorm.app/lib/guava-14.0.1.jar:/Applications/WebStorm.app/lib/gson-2.2.3.jar com.google.jstestdriver.idea.TestRunner --server_url=http://127.0.0.1:9876 --config_files=/Users/tommy/Desktop/work@taobao/turkey-js/jsTestDriver.conf --tests=TestTest
Testing started at 5:52 PM ...
[LOG] before:d
[LOG] after:undefined
[LOG] before:undefined
[LOG] after:undefinedProcess finished with exit code 0
我操 真的是坑爹啊 毁三观