I am trying to add a function to the Object prototype. For now, I'm simply doing this:
Object.prototype.consoleThis = function () {
console.log(this);
};
Then embedding the code into the head
. Then I try to use the new function:
var basicObject = {"name": "basicObject"};
basicObject.consoleThis();
However, in the console, a paragraph element from my HTML has been logged into the console, like so:
<p id="comment" class="ng-binding">
This is a comment
</p>
Which is followed by the expected logging of the basicObject
object. Why is this? How can I stop this from happening?
Edit: Found the source
In my JavaScript, the new function is called like so, including surrounding JavaScript:
$(document).ready(function(){
$("#codeComments").css({height: $(".codeViewPre").height()});
var basicObject = {
"f": "abvc"
};
basicObject.consoleThis();
});
Removing the $("#codeComments").css({height: $(".codeViewPre").height()});
line removes the logged paragraph from the console. Unfortunately, I don't see why this is happening.