How to read javascript code in js libraries ?

Hello & Thanks ,
I am fairly new to javascript coding . And am working with a js library named Quickjs .

I would like to learn how to read/understand any javascript library :

In reference to Quickjs library: https://github.com/dgsprb/quick/wiki/API

My complete source code :slightly_smiling: http://pastebin.com/YezzaXX6
Source code for Quick.js pastebin.com/1fhT2uBY

It occurs to me that maybe I could find out which button was clicked by using the the hasTag method .

But I get into trouble , error: ~paddle-main-NOW.js:63 Uncaught TypeError: RestartBtn.hasTag is not a function

when I try: RestartBtn.prototype.update = function () {

        if (this.pointer.getPush()) {  

// if (GameObject.hasTag(“restartBtn”)) { // doesnt work

// if (this.hasTag(“restartBtn”)) { // doesnt work

		     if (RestartBtn.hasTag("restartBtn")) {  

            alert('restartBTN = ' + restartBTN);  }; }; }; 			    

Pls , tell me why the following works , and the above doesnt ?

Ball.prototype.onCollision = function (GameObject) { 

    var collision = this.getCollision(GameObject); 

    if (GameObject.hasTag("lies02")) { 

	    lies02.setLeft(0);  

Thanks…Vern

From what you’ve pasted, GameObject doesn’t seem to be a global variable. It is passed into the function you are in. For example, onCollision passes in GameObject. Your RestartBtn.prototype.update function doesn’t seem to provide for a GameObject argument.

If you set a breakpoint inside your update function, go to the Console and see what the value of GameObject is and whether it has a hasTag method built on it.

:slightly_smiling:

1 Like

This is very helpful…Thanks

1 Like