0

I wanted to use some data in another JS script which had a JQuery call $(document).ready(function() inside the block, but i did not want to use JQuery nor init the script, because i just wnat to use some of the predefined variables.

So simply using the script from external source ( as it might get changed ) but skipping the ready() call and just do some data manipulation afterwards.

TheBelgarion
  • 310
  • 3
  • 7

1 Answers1

0

I got it working with

<script>
var fakeJquery = function(fn) {
    this.ready = function () {
        return true;
    }
};
var $ = function(fn) { return new fakeJquery();}
</script>

But i wonder if there is a better, easier way to do that?

TheBelgarion
  • 310
  • 3
  • 7
  • 2
    If you just want to mock the interface why would it matter if there was a better/easier way to do it? The function is 5 lines of code. – The Muffin Man Sep 15 '14 at 22:52
  • 1
    You could use jQuery.noConflict() [Reference post: http://stackoverflow.com/questions/7882374/how-do-i-implement-jquery-noconflict]. This would allow you to use your functions without anyconflicts with jQuery functions. – dhruvpatel Sep 15 '14 at 23:01