Jump to content

HOLY ROBIN, BATMAN!


L8V2L
 Share

Recommended Posts

YOU GUYS HAVE A MOBILE VERSION, AND DIDNT TELL ME!!! MMMMMMMAAAHHHH!So I'm reading js pocket version the 3rd edition, and in it, it state; function declaration statements are not true statements, and the ECMAScript specification only allows them as top-level statements. They can appear in global code, or within other functions, but they cannot appear inside of loops, conditionals, or try/catch/finally or with statements. Note that this restriction applies only to functions declared as statements. Function definition expressions may appear anywhere in your JavaScript code.From what I gather is that a function statement is with the var... Binding the function to a variable name. And a function expression declare a function with the function key word. If that's correct, then this is wrong. I but it in an if else statement, and it works. Anyone care to clarbrate(share, talk, etc... Pretty sure I spell that word wrong).

Link to comment
Share on other sites

This is a function statement:

function testfunc() {}
This is a function expression:
var testfunc = function() {}

 

Yes I know... but thinks for typing out, I still get confuse. But this post was referring to what I read in the book, to which I copy and paste it in the opening of this post. I use both of these in an if statement, and they work. The book was incorrect on that; which said it wouldn't work. I'm hopping someone could tell me I read it incorrectly, cause as an novice, it's important to make sure that what I'm reading be the absolute truth.
Link to comment
Share on other sites

A very important point about the Function() constructor is that the functions it creates do not use lexical scoping; instead, they are always compiled as if they were top-level functions: they can access global variables, but not any local variables.What does this mean?

Link to comment
Share on other sites

It means that if you call the Function() constructor inside another function it won't have access to the other function's variables:

function test() {    var x = 3;    var a = new Function("alert(x);");    a(); // Error: x is not defined}test();
  • Like 1
Link to comment
Share on other sites

It means that if you call the Function() constructor inside another function it won't have access to the other function's variables:

function test() {    var x = 3;    var a = new Function("alert(x);");    a(); // Error: x is not defined}test();

 

Thanks! I understand the message cause of your explanation... But not the depth... If you could explain lexical scoping to me. But if not, that's cool.Thanks again for the over all meaning.lexical scoping
Link to comment
Share on other sites

Keep in mind that the ECMAScript specification and a browser's Javascript implementation are not necessarily the same thing. The specification says one thing, but any browser vendor can implement Javascript however they want. Ideally, they all follow the specification. In reality, they don't. Each browser uses its own set of rules even though they might all be based on the ECMAScript specification. IE throws syntax errors that other browsers ignore or allow.

Link to comment
Share on other sites

Keep in mind that the ECMAScript specification and a browser's Javascript implementation are not necessarily the same thing. The specification says one thing, but any browser vendor can implement Javascript however they want. Ideally, they all follow the specification. In reality, they don't. Each browser uses its own set of rules even though they might all be based on the ECMAScript specification. IE throws syntax errors that other browsers ignore or allow.

THATS STUPID!!!!!!Do nodes.js follow the ECMAScript rules? If so.... In others news: take a look at this stupid explanationExample 8-1. A simple JavaScript class
 // range.js: A class representing a range of values.  // This is a factory function that returns a new range object. function range(from, to) {     // Use Object.create() to create an object that inherits     // from the prototype object defined below. The prototype     // is stored as a property of this function, and defines     // the shared methods (behavior) for all range objects.     var r = Object.create(range.methods);     // Save the start and end points (state) of the object.     // They are noninherited properties unique to this object.     r.from = from;     r.to = to;     // Finally return the new object     return r; } // This prototype object defines methods inherited by all // range objects. range.methods = {     // Return true if x is in the range, false otherwise     includes: function(x) {         return this.from <= x && x <= this.to;     },     // Invoke f once for each integer in the range.     // This method works only for numeric ranges.     foreach: function(f) {         for(var x=Math.ceil(this.from); x <= this.to; x++)             f(x);     },     // Return a string representation of the range     toString: function() {         return "(" + this.from + "..." + this.to + ")";     } }; // Here are example uses of a range object. var r = range(1,3);      // Create a range object r.includes(2);           // => true: 2 is in the range r.foreach(console.log);  // Prints 1 2 3 console.log(r);          // Prints (1...3) 
When I go over tutorial and example; I like to write them in the console for hands on. This guy that wrote this is stupid like the broswer. THIS!!!! The bad part about this is I have to finish this stupid book!Can some one explain to me and possible rewrite it so I can have more of a hands on experience.THERE MUST BE BOOKS THAT GIVE NOTHING BUT EXPLANTATION FOR YHE CODE FOLLOW BLY THE CODE AND MORE EXPLANATION. He stay on subject but it could be a lot better.And spell check for this mobile version!
Link to comment
Share on other sites

Keep in mind that the ECMAScript specification and a browser's Javascript implementation are not necessarily the same thing. The specification says one thing, but any browser vendor can implement Javascript however they want. Ideally, they all follow the specification. In reality, they don't. Each browser uses its own set of rules even though they might all be based on the ECMAScript specification. IE throws syntax errors that other browsers ignore or allow.

THATS STUPID!!!!!!Do nodes.js follow the ECMAScript rules? If so.... In others news: take a look at this stupid explanationExample 8-1. A simple JavaScript class
 // range.js: A class representing a range of values.  // This is a factory function that returns a new range object. function range(from, to) {     // Use Object.create() to create an object that inherits     // from the prototype object defined below. The prototype     // is stored as a property of this function, and defines     // the shared methods (behavior) for all range objects.     var r = Object.create(range.methods);     // Save the start and end points (state) of the object.     // They are noninherited properties unique to this object.     r.from = from;     r.to = to;     // Finally return the new object     return r; } // This prototype object defines methods inherited by all // range objects. range.methods = {     // Return true if x is in the range, false otherwise     includes: function(x) {         return this.from <= x && x <= this.to;     },     // Invoke f once for each integer in the range.     // This method works only for numeric ranges.     foreach: function(f) {         for(var x=Math.ceil(this.from); x <= this.to; x++)             f(x);     },     // Return a string representation of the range     toString: function() {         return "(" + this.from + "..." + this.to + ")";     } }; // Here are example uses of a range object. var r = range(1,3);      // Create a range object r.includes(2);           // => true: 2 is in the range r.foreach(console.log);  // Prints 1 2 3 console.log(r);          // Prints (1...3) 
When I go over tutorial and example; I like to write them in the console for hands on. This guy that wrote this is stupid like the broswer. THIS!!!! The bad part about this is I have to finish this stupid book!Can some one explain to me and possible rewrite it so I can have more of a hands on experience.THERE MUST BE BOOKS THAT GIVE NOTHING BUT EXPLANTATION FOR YHE CODE FOLLOW BLY THE CODE AND MORE EXPLANATION. He stay on subject but it could be a lot better.And spell check for this mobile version!
Link to comment
Share on other sites

Keep in mind that the ECMAScript specification and a browser's Javascript implementation are not necessarily the same thing. The specification says one thing, but any browser vendor can implement Javascript however they want. Ideally, they all follow the specification. In reality, they don't. Each browser uses its own set of rules even though they might all be based on the ECMAScript specification. IE throws syntax errors that other browsers ignore or allow.

THATS STUPID!!!!!!Do nodes.js follow the ECMAScript rules? If so.... In others news: take a look at this stupid explanationExample 8-1. A simple JavaScript class
 // range.js: A class representing a range of values.  // This is a factory function that returns a new range object. function range(from, to) {     // Use Object.create() to create an object that inherits     // from the prototype object defined below. The prototype     // is stored as a property of this function, and defines     // the shared methods (behavior) for all range objects.     var r = Object.create(range.methods);     // Save the start and end points (state) of the object.     // They are noninherited properties unique to this object.     r.from = from;     r.to = to;     // Finally return the new object     return r; } // This prototype object defines methods inherited by all // range objects. range.methods = {     // Return true if x is in the range, false otherwise     includes: function(x) {         return this.from <= x && x <= this.to;     },     // Invoke f once for each integer in the range.     // This method works only for numeric ranges.     foreach: function(f) {         for(var x=Math.ceil(this.from); x <= this.to; x++)             f(x);     },     // Return a string representation of the range     toString: function() {         return "(" + this.from + "..." + this.to + ")";     } }; // Here are example uses of a range object. var r = range(1,3);      // Create a range object r.includes(2);           // => true: 2 is in the range r.foreach(console.log);  // Prints 1 2 3 console.log(r);          // Prints (1...3) 
When I go over tutorial and example; I like to write them in the console for hands on. This guy that wrote this is stupid like the broswer. THIS!!!! The bad part about this is I have to finish this stupid book!Can some one explain to me and possible rewrite it so I can have more of a hands on experience.THERE MUST BE BOOKS THAT GIVE NOTHING BUT EXPLANTATION FOR YHE CODE FOLLOW BLY THE CODE AND MORE EXPLANATION. He stay on subject but it could be a lot better.And spell check for this mobile version!
Link to comment
Share on other sites

These things are much too advanced for you. You need to have understanding of Javascript is a language and then you will be able to know what the code is doing. The things you're showing are programs made with Javascript, and all programs are different. In order to know what a program does you have to already have a lot of experience in Javascript.

Ignore that code and try to go back to more basic things.

Link to comment
Share on other sites

Calling test() is equivalent to calling exec() and returning true if the return value of exec() is not null. Because of this equivalence, the test() method behaves the same way as the exec() method when invoked for a global regular expression: it begins searching the specified string at the position specified by lastIndex, and if it finds a match, it sets lastIndex to the position of the character immediately following the match. Thus, you can loop through a string using the test() method just as you can with the exec() method.No it's not! exec(); return an array of items, or null. test(); return a Boolean value!!!!!!! MMMMMMMMMMAAAAAAAAAAAAAWWWWWW!!!!!!!!

Link to comment
Share on other sites

What they're saying is correct. Calling test() is the same as first calling exec() and then returning true if the exec() return value isn't null.

Maybe I don't understand it in that content... You calling test is the same as FIRST calling exec(); calling them both? You're saying while calling them both, exec() first? That what it look like.
Link to comment
Share on other sites

Is English your native language? You seem to have trouble understanding what things are saying.

/* Using test */var a = str.test(exp);alert(a); // Shows "true" or "false"/* Equivalent operation: */var a = true;var e = str.exec(exp);if(e === null) {    a = false;}alert(a); // Shows "true" or "false", the same value as it would in the previous example
Link to comment
Share on other sites

Is English your native language? You seem to have trouble understanding what things are saying.

/* Using test */var a = str.test(exp);alert(a); // Shows "true" or "false"/* Equivalent operation: */var a = true;var e = str.exec(exp);if(e === null) {    a = false;}alert(a); // Shows "true" or "false", the same value as it would in the previous example

 

/* Using test */var str = "js";var exp = /"js"/var a = exp.test(str); alert(a); // Shows "true" or "false"/* Equivalent operation: */var a = true;var e = exp.exec(str);if(e === null) {    a = false;}alert(a); // Shows "true" or "false", the same value as it would in the previous example
Yes... cause of my (refer to signature which will refer you to pic)...
Link to comment
Share on other sites

Because it still is part of the language.

... So I can use it in Node.js for serve scripting, but not in the browser for inline scripting, or external sheet scripting?
Link to comment
Share on other sites

You're able to use it in any environment that uses Javascript. Whether or not it's a good idea is another thing.

So why would Mozilla declare it as so? Or better yet, why would one not use it?
Link to comment
Share on other sites

When something is deprecated it is a notice to programmers that it is scheduled to be removed from a future version, and you should stop using it or change code that already uses it. The MDN reference explains why using the with statement can cause problems.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/withhttp://en.wikipedia.org/wiki/Deprecate

  • Like 1
Link to comment
Share on other sites

When something is deprecated it is a notice to programmers that it is scheduled to be removed from a future version, and you should stop using it or change code that already uses it. The MDN reference explains why using the with statement can cause problems.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/withhttp://en.wikipedia.org/wiki/Deprecate

Thanks
Link to comment
Share on other sites

cars = ["BMW", "Volvo", "Saab", "Ford"];var i = 2;var len = cars.length;var text = ""; // <~~~ Why the empty string again?for (; i < len; i++) {    text += cars[i] + "<br>";}    var text = ""; // <~~~    var i = 0;    while (i < 10) {        text += "<br>The number is " + i;        i++;}
Edited by L8V2L
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...