简体   繁体   中英

TaffyDB, error says TAFFY is not a function

I'm working on a web-based game with HTML, CSS & JavaScript, using Visual Studio. I'm using TaffyDB as a database. However, whenever I try to create a database using the function TAFFY, an error shows up on the console, saying that TAFFY isn't a function. I'm not sure where the mistake is, I believe I've linked the JS files to the HTML correctly, here are all the ways I've tried:

<script type="text/javascript" src="/taffy-min.js"></script>
<script type="text/javascript" src="./taffy-min.js"></script>
<script type="text/javascript" src="taffy-min.js"></script>
<script type="text/javascript" src="https://github.com/typicaljoe/taffydb/blob/master/taffy.js"

I have also tried including the full path, and for all of the above I tried it using 'taffy.js' instead of 'taffy-min.js'. I have also tried it with and without jQuery:

<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>

I am not sure if the mistake is the JS files not linking to the HTML properly, or if it's something entirely different. Code I used to set up a user:

var users = TAFFY([
        {
            "id": 1,
            "user": "John123",
            "level": 5,
            "gameType: "easy"
        }]);

First of all you have missing double quotes here: "gameType: "easy" , should be "gameType": "easy" . The error is saying that TAFFY is not a function: this means that there's another variable in the scope named TAFFY . In order to check if the taffy script is linked correctly open the console and type typeof this.TAFFY which should print "function" . Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM