There is probably a question like this, but I just wanted to ask. Maybe it will be helpful to somebody.
I have this code:
window.WML.namespace('Cards', {}, (function (wml) {
'use strict';
var layout = {
'4': [
[
{x: X_POS_3, y: Y_POS_1}, {x: X_POS_4, y: Y_POS_1},
{x: X_POS_5, y: Y_POS_2}, {x: X_POS_6, y: Y_POS_2}
],
[
{x: X_POS_1, y: Y_POS_1}, {x: X_POS_2, y: Y_POS_1},
{x: X_POS_4, y: Y_POS_2}, {x: X_POS_5, y: Y_POS_2}
],
[
{x: X_POS_2, y: Y_POS_1}, {x: X_POS_5, y: Y_POS_1},
{x: X_POS_4, y: Y_POS_2}, {x: X_POS_5, y: Y_POS_2}
]
],
'5': [
// similar code
]
};
return {
cardLayout: function () {
return layout;
}
};
}(window.WML)));
I could easily do this in Firebug:
var myLayout = WML.Cards.cardLayout();
myLayout['4'] = 34;
console.log(WML.Cards.cardLayout()); // prints {'4': 34, '5': []}
Note:
namespace(ObjectName, inheritObject, newObjectProperties);
Creates subobject inside WML called ObjectName, which inherits properties from inheritObject plus properties/methods from newObjectProperties.
How would you make cardLayout() return object with immutable subarrays, if I know that there is Array.prototype.slice() method which creates shallow copy of caller array?
Object.freezedeveloper.mozilla.org/en-US/docs/Web/JavaScript/Reference/… However, you can still modify arrays though. ButmyLayout['4'] = 34;will not work anymore.