Is the capability to overwrite functions in JavaScript strength or weakness?
<p>I recently came across the following code (from liferay.js) when I was working with Liferay:</p>

<pre><code>....
if (!Liferay._ajaxOld) {
    Liferay._ajaxOld = jQuery.ajax;
}

if (Liferay._ajaxOld) {
    jQuery.ajax = function(options) {
        if (Liferay.Util) {
            options.url = Liferay.Util.getURLWithSessionId(options.url);
        }
        return Liferay._ajaxOld(options);
    };
}
....
</code></pre>

<p>As you can see, the code above overwrites the function "jQuery.ajax" to modify "options.url". One may say this is a strength of the language since we can easily overwrite and customize existing functions.   </p>

<p>However, I would imagine this capability can easily lead to a problem. For instance, my code can overwrite the same function "jQuery.ajax" to modify "options.url" differently from the code above. As a result, any code that expect the behavior defined by "liferay.js" may no longer function as expected. </p>

<p>I see this as a weakness of the language as it does not provide proper encapsulation. 
What are the consensus about this feature/capability of the language in the field?</p>
