In Java you can use a for each loop by saying:
for (elemento e : array)
Also in jQuery:
$.each(arr, function() {
In JavaScript I know I can do:
for (var i = 0; i > 10; i ++)
But is there a way to do a for each in pure JavaScript?
In Java you can use a for each loop by saying:
for (elemento e : array)
Also in jQuery:
$.each(arr, function() {
In JavaScript I know I can do:
for (var i = 0; i > 10; i ++)
But is there a way to do a for each in pure JavaScript?
I have been researching about delegates in C# but the truth is not that clear to me yet.
Can someone explain to me what it is about?
I currently have this function:
function devuelveButaca(posicion){
var array = posicion.split('_');
var row = array[0];
var column = array[1];
var planta = $('#plantaField').val();
var resultado = "";
$.ajax({
type : 'GET',
url : 'site/numButaca',
data : {
planta : planta,
column : column,
row : row
},
success : function(data) {
if(data == 'undefined' || data == ''){
resultado = column;
}else{
resultado = data;
}
},
error : function(request, status, error) {
},
});
alert(resultado);
return resultado;
}
Which returns the result correctly, the problem is that unless it goes into debug mode, or puts an alert before the return, resultado
it returns empty. Currently, the alert exits empty but correctly returns the result (I use it to add the variable text to a div).
I have read that it can be solved by setting a Timeout, but I would like to know if there is a more elegant solution than this.
In some simple applications that I have had to write in C/C++ I have seen the ease with which certain tasks are solved using pointers . Now, more interested in another language: Python, I have noticed the absence of this concept. What is this absence due to? Being Python a very powerful and used language, then, what concept replaces it? Is it implicit in the data types, in the assignments, in the instantiation of a class?
An extremely simple example would be that in C we can code things like this:
#include <stdio.h>
int main(void) {
// your code goes here
int a = 5;
int *b = &a;
printf("a = %d; b = %d\n", a, *b); // (1)
a = 6;
printf("a = %d; b = %d\n", a, *b); // (2)
return 0;
}
(1): a = 5; b = 5
(2): a = 6; b = 6
b
points to the memory address of a
, any modifications to a
can be observed by dereference b
. Any assignment by indirection will *b = <valor>;
modify a
.
But, in Python:
a = 5
b = a
print "a = {0:d}; b = {1:d}".format(a,b) # (1)
b is a # resultado: True
a = 6
print "a = {0:d}; b = {1:d}".format(a,b) # (2)
b is a # resultado: False
(1): a = 5; b = 5
(2): a = 6; b = 5
At the beginning a
and b
refer to the same object. Then when a
it is modified a new object is created; so, both refer to different objects and of different values.
There isn't a way to do what C does in Python with this data type, but it is possible to do something similar with mutable data types; however, it is only possible when we make internal modifications of the mutable data, for example: changing the value of an element of a list.
a = [1, 2]
b = a
print b is a # resultado: True
b.append(3)
print b is a # resultado: True
a = [4, 5]
print b is a # resultado: False
I must save dates and times in different tables of a typical transactional application where I am going to store various information, such as:
I have little experience with MySQL and I'm not sure which data type I should choose in each case.
What is recommended, use a field of type DateTime or type TimeStamp and why?