Jump to content

L8V2L

Members
  • Posts

    788
  • Joined

  • Last visited

Posts posted by L8V2L

  1. Try this:

    function foo() {  function bar() {    console.log('bar scope:');    console.log(this);  }  bar();  this.baz = function() {    console.log('baz scope:');    console.log(this);  }  var bar2 = function() {    console.log('bar2 scope:');    console.log(this);  }  console.log('foo scope:');  console.log(this);}foo();baz();console.log('global scope:');console.log(this);
    The scope is the same for all of them, it is the window object, which is the default scope unless otherwise specified. But even so, they still have a local scope. Even though they run in the window scope, declaring a local variable does not declare it in the window scope. At the end of that it prints the global scope, the window object. Inspect that window object, scroll through the list of properties and methods and see if foo, bar, baz, or bar2 are defined there, and think about why.

     

    Cause this is pointing to the window Object, so only the window's object's inheritance properties and methods will be shown... I don't truly know why, bit that what I think to be. NO wait! I see foo! I will keep what I have already written for documentation purpose like I always do. as stated in the w3s tutorials and many others, the window object is the top object, and in non-strict mode global function or variable will be long to the window object. I don't see bar2. I see baz and foo under function, but not the other two.
  2. The SVG tutorial tells you pretty much all you need to know about SVG. Animation on the web is not done using SVG, it's done by changing the properties of different elements on the page.

    Huh?!You talking about changing tag elements' attributes of SVG tags?
  3. Right.

    Thanks.

    Test it out and see what happens. this refers to the current scope, so if you use console.log(this); inside the function then you can inspect the scope in the developer tools to see if it is defined inside that scope.

    I had a feeling you was going to say that:
    function foo(){function bar(){return(this)};return(bar());};console.log(foo());/*return the window object as assume(<-- feel as if this is the incorrect word to use. But I check it  on my favorite dictionary site, and it is correct, I have trouble with pronunciation to; which is why I misspell a lot). Is this the correct test to perform?*/

    I've always been here, I just don't answer questions if I don't think you will understand the answer.

    HUH! YOU COULD ALEAST TRY! You might be surprise.
  4. what isn't? I don't know what you're trying to say.

    Statement and expression, he have operator in reference, but it's in the wrong place, it should be:expressionoperator <-- or this first, but this make since to have in this order.statementObjectThat way when someone reads down ward, thy are getting it from the simplest understanding from reference to the composite understanding.
  5. Both of those function declarations "work" fine, they just do different things. It's up to you as the programmer to know what you're doing and what you need to use. The difference between those definitions is scope, one of them gets defined in a local scope and one of them in the global scope. If you don't understand scope then further explanation on that won't help, you need to understand scoping. Scoping in Javascript is one of the most important concepts to understand. If you don't understand what a scope is then study it until you do. This is another example of where you need to be writing and testing code and using your browser's developer tools to help you figure out what is going on, reading alone is not sufficient.

    JSG IS BACK!!! YEAH~!! so the one that is an expression with the variable defined out side the function is global, and the other one is local being defined completely in the function it self? What if I put the variable inside the function, would it be defined as a local scope and with that, not work as it does being defined as a global scope?
  6. varName, which is basically the method i used in my earlier post was merely a way to show how you can use closures.funcName, won't work at all. unless it is either a helper function to something else inside the onload or the function is actually assigned while still inside the onload. but by itself it won't workYou are failing to understand what is actually available before the page fully loads. Functions are available before onload runs (even before javascript actually executes any code). Javascript is available before the page even fully loads. but pretty much anything you get by using "document" and it's functions... that has to wait until after the page loads. "function" doesn't need to be inside the window.onload handler, but things like "document.getElementById()" do.both methods can work just fine, its just that you're doing one of them wrong.

    Yes, I remembering that you gotten the code that I ask to work, but I was confuse on why didn't it work the way I had it, but seen that as you said, having setting the variable out of the local scope... comprehending that is another story.

    This seems like a very simple and easy to understand approach, and you could very easily apply a namespace to it.

    comprehending that is another story...Thanks both of you for helping toward understanding it.Both of you get likes from me!!!!
  7. Good suggestion, it is really difficult for us to find the liked posts unless we have used an excel or something else to record the posts.

    Just wanted to comment to you... What are you studying?
  8. most browsers allow you create your own user stylesheet that will override whatever the styles for a given site are.

    Yeah he's right, I start using mines a few days ago... problem is, the background color interfere with text boxes like these, so I can't see what I'm typing.
  9. what are you looking for that you can't find? have you even looked in the reference? I found everything in your post

    • [*]statement -
    http://www.w3schools.com/js/js_statements.asp[*]conditions (not sure what you mean by conduction) - http://www.w3schools.com/js/js_if_else.asp[*]loops - http://www.w3schools.com/js/js_loop_for.asp / http://www.w3schools.com/js/js_loop_while.asp

    and the whole reference of everythinghttp://www.w3schools.com/js/DEFAULT.asp

     

    It's not in reference.
  10. You can simply establish a namespace, and use it, or you can use a closure to establish a namespace and have private static variables and private functions. Why do you need private static variables and private functions? Tell me. Explain it.

    because myFunction is defined inside fin. Why do you have the function wrapped in another function? What is the point? If you had your developer tools and console open, you would see a function not defined error.

    He's trying to use the most advanced stuff he's ever seen in his very first program.

    It's not even that this stuff is advanced per se, it's just not practical, or practically applied.

    you're already doing that by assigning a callback to onload. just assign myFunction to window.onload

    I belive I knowwhere my confusion lies:
    var varName;window.onload = function(){//which one is correct? Please example fully, for this is where my confusion lies.function funcName(){}varName = function(){};}
  11. <!DOCTYPE html><html> <head>  <script>   var changeh1;   function init() {     var cnt=0;      //YES! This is what I wanted... similar to it!     changeh1 = function(){ /*<~~Why fail as "function changeh1()"?*/        document.querySelector("p").innerHTML="success cnt="+(++cnt);     }   }   window.onload = init;  /*To JSG, I TOLD YOU THERE IS AWAY TO DO THE COUNT EXAMPLE LIKE THIS! JA~VA~SCRIPT!!!*/  </script> </head> <body>  <h1>My First JavaScript</h1>  <button type="button" onclick="changeh1()">click me</button>  <h1></h1>  <p></p> </body></html> 
    ...Davej got frustrated-ly mad at me.... even yield at me.
  12. The whole point of using a closure is to avoid using the global space. If you are going to use the global space THEN YOU DON'T NEED A CLOSURE.

    .... No.. I want the onclick to work with out sitting it in JavaScript. I need to have it in a function to be onloaded when the document finishing loading so it can work, but it work out side the function onload... I don't understand why, and don't really feel secure if I wrote code in an external file that it'll function as so.
  13. Go ahead. Try. It just proves that you don't know what you're doing.

    ... I'm ask this question a while back, and did not get no answer. I'm asking why not? Why do I have to define the onclick event in JavaScript? Why can't it be done in the start tag/node/element itself? Why?JAVASCRIPT SERVER SIDE SCRIPTING!!!!!!!!!!!!!!!!!!
  14. <!DOCTYPE html><html><head><script>window.onload = function(){var cnt = 0;function changeh2(){document.getElementById('myh2').innerHTML='success success success, cnt=' + cnt++;}//document.getElementById('btn1').onclick = changeh2;//invoke onclick in the button element/node/tag itself. not in the script tag.}</script></head><body><div><h2 id="myh2">Let's change this text</h2></div><button type="button" id="btn1" onclick="changeh2()">Change Content</button></body></html>
  15. What is the point of it? The function fin() is still sitting there in the global space.

    for the onload event.it should work. Why won't it work and show me how to make it work please.
  16. I want to read it here first, before I venture off to other source i.g. books && tutorial guides, references, manuals, etc.I think it'll be a good ideal for people who know JavaScript to get into serve side scripting, and by introducing it along php and other serve side scripting example equivalents, will encourage them to learn those language as well..So introduce it as serve side scripting, but not with node.js, just mention node.js as a softer ware to make this possible to do. But mostly show case technique to a compulsion this, and other if they exist.More so, try to coerce them into php or the whole server side scripting section.
  17. Well, there is Node.js.

    YES! But introduce it as... Don't all server side scripting need an application or software to operate?I think it'll be a good ideal for people who know JavaScript to get into serve side scripting, and by introducing it alone php and other serve side scripting example equivalents, will encourage them to learn those language as well..So introduce it as serve side scripting, but not with node.js, just mention node.js as a softer ware to make this possible to do. But mostly show case technique to a compulsion this, and other if they exist.More so, try to coerce them into php or the whole server side scripting section.
  18. Why doesn't this work!!!!?????

    <!DOCTYPE html><html><head><script>function fin(){function myFunction(){document.getElementById("myDiv").innerHTML="njinnjknj";}}window.onload = fin;</script></head><body><div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="myFunction()">Change Content</button></body></html>
  19. JavaScript sever side scripting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!JavaScript!!!!!PLEASE JAVASCIRPT SERVER SIDE SCRIPTING!!!!PLEASE!!!!!HE-MAN: THE POWER!!!!!!!!!!!!You could write it parallel to php server side scripting tutorial examples and use that to get people to want to go through php, and the other server side scripting languages.

×
×
  • Create New...