1
問題
每當我打電話arrayGuide
我得到一個error
如何通過原型傳遞多維數組?
Array.prototype.arrayGuide = function() {
console.log(this) // When called… this should be getting logged.
}
//How to get this prototype to work
replace = {
basic: {
stage1: {
one: ["hello", "world"],
two: ["brother", "sister"],
three: ["baby", "adult"]
},
stage2: {
one: ["1"],
two: ["2"],
three: ["3"]
}
},
advanced: {
humans: [/^biology\s/gi, /science$/i]
}
}
replace.arrayGuide() // This keeps throwing an error message
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
結果我應該得到
我應該從第一個演示中獲得這些結果。但由於某種原因,我不是。
function arrayRegExpCreator(place) {
console.log(place) // I should be getting this…
}
replace = {
basic: {
stage1: {
one: ["hello", "world"],
two: ["brother", "sister"],
three: ["baby", "adult"]
},
stage2: {
one: ["1"],
two: ["2"],
three: ["3"]
}
},
advanced: {
humans: [/^biology\s/gi, /science$/i]
}
}
arrayRegExpCreator(replace)
值得一提的是,原生對象的原型是不能修改的從未延長原生對象的原型,如果它不是一個填充工具 – Voreny