Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var functionOne = function() {
- // Some code
- };
- function functionTwo() {
- // Some code
- }
- <script>
- // Error
- functionOne();
- var functionOne = function() {
- };
- </script>
- <script>
- // No error
- functionTwo();
- function functionTwo() {
- }
- </script>
- <script>
- "use strict";
- if (test) {
- // Error
- function functionThree() { doSomething(); }
- }
- </script>
- function xyz(){
- function abc(){};
- // abc is defined here...
- }
- // ...but not here
- var xyz = function abc(){};
- var xyz = function abc(){
- // xyz is visible here
- // abc is visible here
- }
- // xyz is visible here
- // abc is undefined here
- function abc(){};
- var xyz = abc;
- console.log(xyz === abc); // prints "true"
- function abc(){};
- console.log(abc.name); // prints "abc"
- var abc = function(){};
- console.log(abc.name); // prints ""
- // assume really.long.external.scoped is {}
- really.long.external.scoped.name = function shortcut(n){
- // let's call itself recursively:
- shortcut(n - 1);
- // ...
- // let's pass itself as a callback:
- someFunction(shortcut);
- // ...
- }
- function abc(){}
- // we can call it here
- abc(); // works
- // yet it is defined down there
- function abc(){}
- // we can call it again
- abc(); // works
- var xyz = function(){};
- // we can't call it here
- xyz(); // UNDEFINED!!!
- // now it is defined
- xyz = function(){}
- // we can call it here
- xyz(); // works
- var xyz = function abc(){};
- console.log(xyz.name); // prints "abc"
- var abc = function(){};
- abc = function(){};
- function abc(){};
- alert(typeof foo); // 'function', it's already available
- alert(typeof bar); // 'undefined'
- function foo () {}
- var bar = function () {};
- alert(typeof bar); // 'function'
- function test () {}
- test = null;
- (function(){
- var exports = {};
- function privateUtil() {
- ...
- }
- exports.publicUtil = function() {
- ...
- };
- return exports;
- })();
- function x() {
- console.log('x');
- }
- x(); // Works even though it's above the declaration
- function x() {
- console.log('x');
- }
- if (someCondition) {
- function foo() { // <===== INVALID AND WILL FAIL ON
- } // MANY ENGINES
- }
- var y = function () {
- console.log('y');
- };
- var z = function w() {
- console.log('zw')
- };
- var z = function w() {
- console.log(typeof w); // "function"
- };
- console.log(typeof w); // "undefined"
- var MyNamespace = {}
- MyNamespace.foo= function() {
- }
- var MyNamespace {
- foo: function() {
- },
- ...
- }
- functionTwo();
- function functionTwo() {
- }
- functionOne(); --------------- var functionOne;
- | is actually | functionOne();
- var functionOne = function(){ | interpreted |-->
- }; | like | functionOne = function(){
- --------------- };
- functionTwo(); --------------- function functionTwo() {
- | is actually | };
- function functionTwo() { | interpreted |-->
- } | like | functionTwo();
- ---------------
- if (condition){
- function myfunction(){
- // some code
- }
- }
- if (condition){
- var myfunction = function (){
- // some code
- }
- }
- var foo = 1;
- function bar() {
- if (!foo) {
- var foo = 10 }
- return foo; }
- bar() // 10
- function f() {
- return a;
- function a() {return 1};
- var a = 4;
- function a() {return 2}}
- f()() // 2
- function f() {
- return a;
- var a = 4;
- function a() {return 1};
- function a() {return 2}}
- f()() // 2
- function f() {
- var a = 4;
- function a() {return 1};
- function a() {return 2};
- return a; }
- f() // 4
- var a = 1;
- function b() {
- a = 10;
- return;
- function a() {}}
- b();
- a // 1
- function abc(){}
- var abc = function() {};
- //this will work
- abc(param);
- function abc(){}
- //this would fail
- abc(param);
- var abc = function() {}
- var ninja = {
- yell: function(n){
- return n > 0 ? ninja.yell(n-1) + "a" : "hiy";
- }
- };
- assert( ninja.yell(4) == "hiyaaaa", "A single object isn't too bad, either." );
- var samurai = { yell: ninja.yell };
- var ninja = null;
- try {
- samurai.yell(4);
- } catch(e){
- assert( false, "Uh, this isn't good! Where'd ninja.yell go?" );
- }
- var ninja = {
- yell: function yell(n){
- return n > 0 ? yell(n-1) + "a" : "hiy";
- }
- };
- assert( ninja.yell(4) == "hiyaaaa", "Works as we would expect it to!" );
- var samurai = { yell: ninja.yell };
- var ninja = {};
- assert( samurai.yell(4) == "hiyaaaa", "The method correctly calls itself." );
- function foo() {
- return 3;
- }
- //anonymous function expression
- var a = function() {
- return 3;
- }
- //named function expression
- var a = function foo() {
- return 3;
- }
- //self invoking function expression
- (function foo() {
- alert("hello!");
- })();
- var objectOne = new functionOne();
- console.log(objectOne.__proto__); // prints "Object {}" because constructor is an anonymous function
- var objectTwo = new functionTwo();
- console.log(objectTwo.__proto__); // prints "functionTwo {}" because constructor is a named function
- var functionOne = function() {
- // Some code
- };
- var one = new functionOne();
- function functionTwo() {
- // Some code
- }
- two = new functionTwo();
- [].forEach(function iterator() {});
- 'use strict';
- var a = function () {
- throw new Error();
- },
- b = function b() {
- throw new Error();
- },
- c = function d() {
- throw new Error();
- },
- e = {
- f: a,
- g: b,
- h: c,
- i: function () {
- throw new Error();
- },
- j: function j() {
- throw new Error();
- },
- k: function l() {
- throw new Error();
- }
- },
- m = (function () {
- return function () {
- throw new Error();
- };
- }()),
- n = (function () {
- return function n() {
- throw new Error();
- };
- }()),
- o = (function () {
- return function p() {
- throw new Error();
- };
- }());
- console.log([a, b, c].concat(Object.keys(e).reduce(function (values, key) {
- return values.concat(e[key]);
- }, [])).concat([m, n, o]).reduce(function (logs, func) {
- try {
- func();
- } catch (error) {
- return logs.concat('func.name: ' + func.name + 'n' +
- 'Trace:n' +
- error.stack);
- // Need to manually log the error object in Nitro.
- }
- }, []).join('nn'));
- func.name:
- Trace:
- Error
- at a (http://localhost:8000/test.js:4:11)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: b
- Trace:
- Error
- at b (http://localhost:8000/test.js:7:15)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: d
- Trace:
- Error
- at d (http://localhost:8000/test.js:10:15)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name:
- Trace:
- Error
- at a (http://localhost:8000/test.js:4:11)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: b
- Trace:
- Error
- at b (http://localhost:8000/test.js:7:15)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: d
- Trace:
- Error
- at d (http://localhost:8000/test.js:10:15)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name:
- Trace:
- Error
- at e.i (http://localhost:8000/test.js:17:19)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: j
- Trace:
- Error
- at j (http://localhost:8000/test.js:20:19)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: l
- Trace:
- Error
- at l (http://localhost:8000/test.js:23:19)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name:
- Trace:
- Error
- at http://localhost:8000/test.js:28:19
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: n
- Trace:
- Error
- at n (http://localhost:8000/test.js:33:19)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27
- func.name: p
- Trace:
- Error
- at p (http://localhost:8000/test.js:38:19)
- at http://localhost:8000/test.js:47:9
- at Array.reduce (native)
- at http://localhost:8000/test.js:44:27 test.js:42
- func.name:
- Trace:
- a@http://localhost:8000/test.js:4:5
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: b
- Trace:
- b@http://localhost:8000/test.js:7:9
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: d
- Trace:
- d@http://localhost:8000/test.js:10:9
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name:
- Trace:
- a@http://localhost:8000/test.js:4:5
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: b
- Trace:
- b@http://localhost:8000/test.js:7:9
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: d
- Trace:
- d@http://localhost:8000/test.js:10:9
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name:
- Trace:
- e.i@http://localhost:8000/test.js:17:13
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: j
- Trace:
- j@http://localhost:8000/test.js:20:13
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: l
- Trace:
- l@http://localhost:8000/test.js:23:13
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name:
- Trace:
- m</<@http://localhost:8000/test.js:28:13
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: n
- Trace:
- n@http://localhost:8000/test.js:33:13
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: p
- Trace:
- p@http://localhost:8000/test.js:38:13
- @http://localhost:8000/test.js:47:9
- @http://localhost:8000/test.js:54:1
- func.name: undefined
- Trace:
- Error
- at a (http://localhost:8000/test.js:4:5)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at b (http://localhost:8000/test.js:7:9)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at d (http://localhost:8000/test.js:10:9)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at a (http://localhost:8000/test.js:4:5)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at b (http://localhost:8000/test.js:7:9)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at d (http://localhost:8000/test.js:10:9)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at e.i (http://localhost:8000/test.js:17:13)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at j (http://localhost:8000/test.js:20:13)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at l (http://localhost:8000/test.js:23:13)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at Anonymous function (http://localhost:8000/test.js:28:13)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at n (http://localhost:8000/test.js:33:13)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name: undefined
- Trace:
- Error
- at p (http://localhost:8000/test.js:38:13)
- at Anonymous function (http://localhost:8000/test.js:47:9)
- at Global code (http://localhost:8000/test.js:42:1)
- func.name:
- Trace:
- a@http://localhost:8000/test.js:4:22
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: b
- Trace:
- b@http://localhost:8000/test.js:7:26
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: d
- Trace:
- d@http://localhost:8000/test.js:10:26
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name:
- Trace:
- a@http://localhost:8000/test.js:4:22
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: b
- Trace:
- b@http://localhost:8000/test.js:7:26
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: d
- Trace:
- d@http://localhost:8000/test.js:10:26
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name:
- Trace:
- i@http://localhost:8000/test.js:17:30
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: j
- Trace:
- j@http://localhost:8000/test.js:20:30
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: l
- Trace:
- l@http://localhost:8000/test.js:23:30
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name:
- Trace:
- http://localhost:8000/test.js:28:30
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: n
- Trace:
- n@http://localhost:8000/test.js:33:30
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
- func.name: p
- Trace:
- p@http://localhost:8000/test.js:38:30
- http://localhost:8000/test.js:47:13
- reduce@[native code]
- global code@http://localhost:8000/test.js:44:33
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement