I've noticed strange bug while setting a new value to a variable. Unfortunately the Value has been copied to a different variable as well. Do you have an idea what is going on here?
Here are some screen shots while debugging. One just before setting the new value and one just after. You can see how automatically the value has been copied to 2 different variables.
Here is the file if you want to check it yourself:
docs.google.com/spreadsheets/d/17L7KDVteaYUuBE8v5jRRUGBBHa5_Dg6dH0eQ8oDTde4/edit?usp=sharing
Thanks in advance guys
This is not a bug.
Assigning arrays to variables happens by reference (to a memory location) in JavaScript and most other programming languages.
Consider this simplified example
a=[1];
b=a;
b[0]=2;
a is now [2]
To assign a copy you need to create a copy for example using slice
c=a.slice();
c[0]=3;
a will now still be [2] and c will be [3].
So try
red = temp[i].slice();
Related
I know if I pass {{variable}} (like a {{event.text}}) in args field of action form works fine.
But, when I try concatenate this variable with a another String, this not work.
Result in {{state.api_url}}/users string, and I need http//myapi.com/users
Is it possible?
I may have an extremely kludgy workaround for this based on bad javascript.
I was looking to iterate a temp variable downwards. I did the assignment in the raw code box for a transition
Good code like temp.variable==1 would be a true/false test.
But just using one equals sign performs the assignment.
So temp.variable=temp.variable-1 in the raw code box subtracted one from my (numeric value) variable.
This seems to return False for the purposes of the transition so it doesn't matter where you point it as long as it's in the chain.
It seems to work for me, anyway.
I'm properly not sure what your code would look like, perhaps you make a new variable then do a transition with
temp.variable_you_just_made=state.api_url+'/users'
then call that variable doing your url thing?
[Looking around I come to suspect the correct thing would be to make a new action https://botpress.io/docs/10.0/getting_started/trivia_actions/ but I am new to all this]
When I visit some page, like an SPA, I know some objects are added to window by its code.
Is there a way to know what are native browser objects/methods, and which were added by the app?
calling the window variable basicly give you an overview from all the content inside of it. I guess if you want to known how much functions it currently includes you could do something like:
Object.keys(window).length; //or just Object.keys for the names
To known if new functions have been added to the window object need to known the number of keys their where before they where included or just by knowning the static number. To just give some example. Here on stackoverflow the window object only contains 246 keys. However on something like google I counted 1597 keys. So it really depends on the app you are using.
So what you could do is write a function that checks if the amount of keys have been increased and when that happends taking out the key and moving it into a array inside the function.
That just what I get from your question.
I think you are looking for Mutation Observers. With them you can listen for newly added or removed DOM elements. I believe you also get notified of attribute and text changes.
Here is a link to a short article about them. Mutation Observers
Hope this helps!
Suppose you have two separate tabs. One that doesn't add anything to window (which is hard to find), one that have added some properties.
have both open.
in the clean one do :
a = Object.keys(window);
JSON.stringify(a);
copy the result and move that to the tab that have added some properties to window. then do a = JSON.parse(<Ctrl + v>)
and b = Object.keys(window)
and finally :
c = b.filter(p=>a.indexOf(p)=== -1)
now c contains names of all properties that have been added to window object by that tab;
HOT TIP:
Firefox Developer Edition does that by default :
a screenshot of how it works
Note that window's default properties are separated in a different property (called [default properties])
in my code I was always doing
for(i in vector)...
and it always worked, but the problem is that it somehow changed and now my for shows all the values but also the properties, like "remove" that is a function, and it is breaking my whole code.
I don't know why it suddenly changed, because I didn't do anything and I'm getting crazy with this already.
Do you guys know what is happening with my application?
Another thing is that the code only get this problem on my computer.
If I clone my repository again and try it works for while but then starts the problem again.
Thank you.
The in operator has always had this behaviour. Just check that the property exists directly on the object instead of on the prototype:
for (var i in vector) {
if (vector.hasOwnProperty(i)) {
// Property exists on object
}
}
That should solve your issues.
Tom
So, I have to find all possible cycles in not directed graph, that starts (and ends) at chosen vertex.
I have written an algorithm for it in js: jsfiddle
But faced very, very weird problem: in my recursive function, argument changes itself somehow! But I dont even touch it! Pls help me, I am suffering with this bug for 16 hours already! :(
I thinkm that this arguments is changed by this code:
cycle.push(vertex);
But it should not! Becuase in his visibility area the global cycle variable must be overwritten by local one!
Here's the issue:
var newCycle = cycle;
You're not cloning it, you're just giving the same object a different name. Try:
var newCycle = cycle.slice(0);
This is driving me insane. I am trying to grab an object in javascript using a dynamic variable. Static variables appear to work, yet I cant for the life of me see the difference between the static vars I put in and the dynamic vars.
My snippet below better illustrates the issue
console.log(itemId); //E2
console.log(typeof itemId); //string
console.log(typeof 'E2'); //string
console.log(ganttObject.items['E2']); //object [with data]
console.log(ganttObject.items[itemId]); //undefined
The weird thing is that I have extensively used dynamic calling of objects elsewhere in the script, but it is breaking here.
Tested in Safari & Chrome
Works for me in FF4:
Are you sure you don't have a typo or something in your actual code?
I found the answer at last by tracing the value of itemId to the source. Turns out an edit in the html generation added a space after my id.
Moral of the story:
Remember that trailing spaces won't show up on the console window