I'm new to JavaScript.
I'm currently working on something that requires the following:
In JavaScript if my code structure looks as below and I may only write in code_1, is it possible to alter the way get and set methods are used to assign a property to an object, z, without changing a function, foo(z), in not_my_code? I can decide z in code_1, but I want to change the way its properties are assigned in foo(z).
I've read about using Object.prototype in some way, but since I'm very new to JavaScript this was my initial approach which probably is completely wrong since it doesn't work!
<script>
\\ code_1
var z;
Object.prototype = {
// change the Object prototype behaviour when z is get or set in foo
get: function() {
// do something when z is used in foo
// like output a console.log message
}
}
</script>
<script>
\\ not_my_code
var bar = ( function() {
foo : function(z) {// z is used}
})();
</script>