JavaScript References Más videos
Descripción del tema
Definition
Physically all the objects are stored in the memory and we can have access to them through a reference, which is contained in a variable. Multiple variables can have a reference to the same object and this object may contain references to other objects like strings, number, arrays, etc.. When multiple variables point to the same object and it is modified, the change will be reflected in all the variables that have a reference to the object. One example of this is://We create an empty object var obj = {}; //We create a reference var reference = obj; //We add a property to the original object obj.property = 1; //The reference can have access to the property we created previously console.debug('reference.property = '+reference.property);The same principle applies to the arrays, even though they modify themselves through the method "push" the references will be affected. Let's analyze the next example:
var array = ['Ext JS','Mootools','jQuery']; var ref = array; array.push('prototype'); console.debug(ref.length == array.length); console.debug(ref);
Only references to objects
It is important to mention that in JavaScript the references only point to objects that are in memory not to the other references like the language C/C++. The next example shows this behavior://We create the original object var obj1 = {property:'Original value'}; //We make a reference to the original object var ref1 = obj1; //obj1 points to a New object obj1 = {property:'New Object!'}; //Ref1 points to the original object, therefore they're different console.debug('same object = '+(obj1.property == ref1.property)); console.debug(obj1.property); console.debug(ref1.property);
Concatenation
The strings are objects too and we have a reference to them through a variable; it is important to remember when we concatenate one or more strings the result will always be a new object. The next example shows that when we concatenate a text we create a new string and therefore the reference is pointing to the original string.var str = 'Hello world!'; var refStr = str; str += ' this is Crysfel'; console.debug('same string = '+(str === refStr));If you have any questions or suggestions about this chapter, go ahead and ask them in the comments, I'd be glad to answer them.
Te gustaría recibir más tutoriales como este en tu correo?
Este tutorial pertenece al curso Learning Ext JS 3, te recomiendo revises el resto de los tutoriales ya que están en secuencia de menor a mayor complejidad.
Si deseas recibir más tutoriales como este en tu correo te recomiendo registrarte al curso, si ya eres miembro solo identifícate y registrate al curso, si no eres miembro te puedes registrar gratuitamente!
Si no gustas registrarte en este momento no es necesario! Aún así puedes recibir los nuevos tutoriales en tu correo! Jamás te enviaremos Spam y puedes cancelar tu suscripción en cualquier momento.
Regístrate a este curso
Este tutorial pertenece al curso Learning Ext JS 3, revisa todos los tutoriales que tenemos en este mismo curso ya que están en secuencia y van de lo más sencillo a lo más complicado.
Tendrás acceso a descargar los videos, códigos y material adicional.
Podrás resolver los ejercicios incluidos en el curso así como los Quizzes.
Llevarás un registro de tu avance.
3Comentarios
i am having some misconception like in starting you explained that whatever we assign to object it will updated to reference variable but last 2 ex. its reverse please explain it.
great,nice information, good learning javascript for beginner
I have the same question as puran Apr 09, 2010 "at the begining you explained that whatever we assign to object it will updated to reference variable but last 2 ex. its reverse please explain it"