-
-
Save os0x/701949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function EXArray() { | |
var result = []; | |
result.__proto__ = EXArray.prototype; | |
for (var i = 0, len = arguments.length; i < len; ++i) { | |
result[i] = arguments[i]; | |
} | |
return result; | |
} | |
// どうせなら仕様の範囲内で | |
EXArray.prototype = new Array(); | |
EXArray.prototype.constructor = EXArray; | |
Object.defineProperties(EXArray.prototype, { | |
item : { | |
value: function item(i) { | |
return this[i]; | |
}, | |
writable: true, | |
configurable: true | |
} | |
}); | |
function assert(msg, bool) { | |
print(msg + ': ' + (bool ? 'OK' : 'NG')); | |
} | |
function test_hasOwnProperty() { | |
var a = new EXArray('a'); | |
assert('a.hasOwnProperty(0)', a.hasOwnProperty(0)); | |
a.push('b'); | |
assert('a.hasOwnProperty(1)', a.hasOwnProperty(1)); | |
print('a.item(0) is ' + a.item(0)); | |
assert('a.item(0) == "a"', a.item(0) === 'a'); | |
assert('a.toString() === "a,b"', a.toString() === 'a,b'); | |
} | |
function test_instanceof() { | |
var a = new EXArray(); | |
assert('a instanceof Array', (a instanceof Array)); | |
assert('a instanceof EXArray', (a instanceof EXArray)); | |
} | |
function test_JSON() { | |
var a = new EXArray(); | |
a.push("a"); | |
a.push("b"); | |
assert('JSON.stringify(a)', JSON.stringify(a) === '["a","b"]'); | |
} | |
function test_toSource() { | |
var a = new EXArray(); | |
a.push("a"); | |
a.push("b"); | |
print(a.toSource()); | |
assert('a.toSource()', a.toSource() === '["a", "b"]'); | |
} | |
test_hasOwnProperty(); | |
test_instanceof(); | |
(function() { | |
for (var key in this) { | |
if (key.indexOf('test') === 0 && typeof this[key] === 'function') { | |
print('===== ' + key + ' ========'); | |
this[key](); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment