PDA

View Full Version : can anyone here tell me about this strange javascript character? i'm confusing



smansakra
02-03-2009, 03:11 AM
i'm new on javascript so i 'm little confusing about this little strange javascript characters:

plese , can anyone here tell / explain this to me?

var $name --> i dont know why javascript use "$" character? it look like php variable.. humk?:confused:

&$name --> oh my good, i'm really confusing about this :eek:

parent :: parse($name) -- >:( plese tellme.....

$$this ---> what does it mean????


and alse what is "prototype" ?
and what is "jquery"?

sorry, i'm a new player in javascript.

Nile
02-03-2009, 03:13 AM
Prototype and Jquery are both javascript frameworks (http://en.wikipedia.org/wiki/JavaScript_Framework). A simpler way to use javascript. The $ variables are for frameworks - jquery uses it as a selector.


$("#div");

Which would mean: document.getElementById('div').

smansakra
02-03-2009, 03:28 AM
Prototype and Jquery are both javascript frameworks (http://en.wikipedia.org/wiki/JavaScript_Framework). A simpler way to use javascript. The $ variables are for frameworks - jquery uses it as a selector.


$("#div");

Which would mean: document.getElementById('div').


hum, prototype and jquery is frameworks, okay i will read your link above.
$("#div"); is used by jquery as selector , same as document.getElementById('div')


so what about :

var $name
&$name
parent :: parse($name)
$$this


:confused::confused::confused::confused::confused:

Nile
02-03-2009, 03:31 AM
Can you point me to where you've seen that before? You may be getting mixed up with PHP Classes (or OOP) (http://us2.php.net/zend-engine-2.php).


<?php
class Test {
var $error;
function carry_error($err){
$this->error .= $err."<br />";
}
function throw_errors(){
return MakeErrors::error($this->error);
}
}
class MakeErrors {
function error($err){
return $err;
}
}
$test = new Test();
$test->carry_error('Some random error...');
$test->carry_error('One more random error.. :-)');
die($test->throw_errors());
?>

smansakra
02-03-2009, 03:38 AM
hi, sorry, i think i'm really confusing , hi may be you're right, this is php class

sorry....

Nile
02-03-2009, 03:38 AM
Can you post the code you saw with this code? Our job is to unconfuse confused people. :)

codeexploiter
02-03-2009, 04:00 AM
var $name --> i dont know why javascript use "$" character? it look like php variable.. humk?

A JavaScript variable name can start with $ symbol. In PHP without $ symbol it is not possible to make variable (I know constants does not have them) but in JavaScript the $ symbol is not compulsory. Rather we can say it like this in PHP $ symbol is not a part of the 'variable name' but in JavaScript if you use $ symbol it will be a part of the 'variable name'

smansakra
02-03-2009, 04:09 AM
var $name :


/**
* search the forum
*/
Forum.prototype.search = function (text, type, forum, u, disp)
{
this.loading ('SEARCHING');

var m = document.getElementById('main');
if (!m)
{
new BxError("main div is not defined", "please name main content container");
}

var $this = this;

var h = function (r)
{
var m = document.getElementById('main');

m.innerHTML = r;

$this.runScripts ('main');

$this.setWindowTitle(null);

$this.stopLoading ();

$this.checkHeight ();
}

new BxXslTransform(this._base + "?action=search&text=" + text + "&type=" + type + "&forum=" + forum + "&u=" + u + "&disp=" + disp, urlXsl + "search.xsl", h);

document.h.makeHist('action=goto&search_result=1&' + text + '&' + type + '&' + forum + '&' + u + '&' + disp);

return false;
}


huh, i forget about the sample code of
&$name
parent :: parse($name)
$$this

i'm still confusing so i can not think . he he

Nile
02-03-2009, 04:13 AM
Yes, as you see where you've bolded. They are using this to get to a parent element you cannot access from a function.

Want english?

It's just like saying I'm gonna destroy Jupiter.. But wait, I'm on Earth! You cannot do that, so what you have to do is put a few bombs on Jupiter - then leave to earth.

[offtopic w/ a little bit of my two cents]
Like my example. Very destructive, but Jupiter is my least favorite big giant gas planet. :) (or really least favorite planet)
Of course, looking at the fact that Jupiter is made out of gas, and if I planted bombs on it, it'd probably explode before I have time to escape... What ever! GR, it's just an example.
[/3 cents. :)]

smansakra
02-03-2009, 04:17 AM
A JavaScript variable name can start with $ symbol. In PHP without $ symbol it is not possible to make variable (I know constants does not have them) but in JavaScript the $ symbol is not compulsory. Rather we can say it like this in PHP $ symbol is not a part of the 'variable name' but in JavaScript if you use $ symbol it will be a part of the 'variable name'


so? why do they ( designer) use this "$" on the variable name?
hum, may be they (designer) want to make somebody like me to be confusing when reading their code:confused:

smansakra
02-03-2009, 04:20 AM
Want english?

It's just like saying I'm gonna destroy Jupiter.. But wait, I'm on Earth! You cannot do that, so what you have to do is put a few bombs on Jupiter - then leave to earth.

[offtopic w/ a little bit of my two cents]
Like my example. Very destructive, but Jupiter is my least favorite big giant gas planet. :) (or really least favorite planet)
Of course, looking at the fact that Jupiter is made out of gas, and if I planted bombs on it, it'd probably explode before I have time to escape... What ever! GR, it's just an example.
[/3 cents. :)]


this will make me more confusing:confused:

Nile
02-03-2009, 04:20 AM
No, they used it because it's probably there way of coding. Some people use:


var that = this;
var.onclick = function() { that.blah };

Some people use:


var parentThis = this;
var.onclick = function() { parentThis.blah };


It's just a personal preference.

smansakra
02-03-2009, 04:22 AM
Want english?

It's just like saying I'm gonna destroy Jupiter.. But wait, I'm on Earth! You cannot do that, so what you have to do is put a few bombs on Jupiter - then leave to earth.

[offtopic w/ a little bit of my two cents]
Like my example. Very destructive, but Jupiter is my least favorite big giant gas planet. :) (or really least favorite planet)
Of course, looking at the fact that Jupiter is made out of gas, and if I planted bombs on it, it'd probably explode before I have time to escape... What ever! GR, it's just an example.
[/3 cents. :)]


THIS WILL MAKE ME MORE CONFUSING :confused:

Nile
02-03-2009, 04:23 AM
Ok, so then ignore it :).

This is to get the current function/elements its currently editing. Just like if you were pointing to something and saying this. If you were pointing to a table and said "This is very good for sitting on," but you were talking about the char under the table...

I hope that's a better - if not just forget that I even said it.

smansakra
02-03-2009, 04:25 AM
hum, may be i should study javascript
i need to take a rest to make my little brain better to think something

cheerr!!

Nile
02-03-2009, 04:26 AM
Haha - aren't you already?

jscheuer1
02-03-2009, 07:37 AM
BTW folks, in jQuery:

$('#some_id')

is not the same as:

document.getElementById('some_id')

The $ function returns a jQuery object that references the element or elements as an array upon which the various jQuery functions may be run. It's more complex than that, but as a simple example:

$('#some_id').width()

returns the element's layout width.

document.getElementById('some_id').width()

throws an error.

Nile
02-03-2009, 12:57 PM
Yes - I was really using that as an example. But correct. Just like:


$("#page-wrap #links a")

!=


document.getElementById("#page-wrap #links a");

Snookerman
02-03-2009, 04:04 PM
I always thought that when you use id:s with jQuery, it used the getElementById, this is mostly where I got that from:
http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx#tip8 (http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx#tip8)

jscheuer1
02-03-2009, 04:15 PM
jQuery may use getElementById (when possible - instead of traversal - to find the element), but it does more. It extends the object as an array for use with the other jQuery functions. Nile's example isn't so good in this regard, because there is no equivalent getElementById syntax that even approximates that result, however:

$("#page-wrap #links a")

still returns an array object which is extended for use with the other jQuery functions.

The important thing is that we have an extended array object, not a standard, single element object, as we do get with getElementById.

smansakra
02-04-2009, 05:50 AM
hum? . . . . . .

smansakra
02-04-2009, 06:06 AM
so, what about character like these below, i'm sure these character are not only on php but javascript too, somedays agao i read a javascript code, but i forget that js file so i'm little difficult to include an example here


&$name

parent :: parse($name)

$$this

jscheuer1
02-04-2009, 07:30 AM
None of these have any standard meaning in javascript:



&$name

parent :: parse($name)

$$this

smansakra
02-04-2009, 07:52 AM
may be i was wrong, that's php not javascript , sorry..