Advertisement
Guest User

Untitled

a guest
Apr 13th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.58 KB | None | 0 0
  1. var functionOne = function() {
  2. // Some code
  3. };
  4.  
  5. function functionTwo() {
  6. // Some code
  7. }
  8.  
  9. <script>
  10. // Error
  11. functionOne();
  12.  
  13. var functionOne = function() {
  14. };
  15. </script>
  16.  
  17. <script>
  18. // No error
  19. functionTwo();
  20.  
  21. function functionTwo() {
  22. }
  23. </script>
  24.  
  25. <script>
  26. if (test) {
  27. // Error or misbehavior
  28. function functionThree() { doSomething(); }
  29. }
  30. </script>
  31.  
  32. function xyz(){
  33. function abc(){};
  34. // abc is defined here...
  35. }
  36. // ...but not here
  37.  
  38. var xyz = function abc(){};
  39.  
  40. var xyz = function abc(){
  41. // xyz is visible here
  42. // abc is visible here
  43. }
  44. // xyz is visible here
  45. // abc is undefined here
  46.  
  47. function abc(){};
  48. var xyz = abc;
  49.  
  50. console.log(xyz === abc); // prints "true"
  51.  
  52. function abc(){};
  53. console.log(abc.name); // prints "abc"
  54.  
  55. var abc = function(){};
  56. console.log(abc.name); // prints ""
  57.  
  58. // Assume really.long.external.scoped is {}
  59. really.long.external.scoped.name = function shortcut(n){
  60. // Let it call itself recursively:
  61. shortcut(n - 1);
  62. // ...
  63. // Let is pass itself as a callback:
  64. someFunction(shortcut);
  65. // ...
  66. }
  67.  
  68. function abc(){}
  69.  
  70. // We can call it here
  71. abc(); // Works
  72.  
  73. // Yet, it is defined down there.
  74. function abc(){}
  75.  
  76. // We can call it again
  77. abc(); // Works
  78.  
  79. // We can call it here
  80. abc(); // Works
  81. return;
  82. function abc(){}
  83.  
  84. var xyz = function(){};
  85.  
  86. // We can't call it here
  87. xyz(); // UNDEFINED!!!
  88.  
  89. // Now it is defined
  90. xyz = function(){}
  91.  
  92. // We can call it here
  93. xyz(); // works
  94.  
  95. var xyz = function abc(){};
  96. console.log(xyz.name); // Prints "abc"
  97.  
  98. var abc = function(){};
  99.  
  100. abc = function(){};
  101.  
  102. function abc(){};
  103.  
  104. function x() {
  105. console.log('x');
  106. }
  107.  
  108. x(); // Works even though it's above the declaration
  109. function x() {
  110. console.log('x');
  111. }
  112.  
  113. if (someCondition) {
  114. function foo() { // <===== INVALID AND WILL FAIL ON
  115. } // MANY ENGINES
  116. }
  117.  
  118. var y = function () {
  119. console.log('y');
  120. };
  121.  
  122. var z = function w() {
  123. console.log('zw')
  124. };
  125.  
  126. var z = function w() {
  127. console.log(typeof w); // "function"
  128. };
  129. console.log(typeof w); // "undefined"
  130.  
  131. var obj = {
  132. value: 0,
  133. get f() {
  134. return this.value;
  135. },
  136. set f(v) {
  137. this.value = v;
  138. }
  139. };
  140. console.log(obj.f); // 0
  141. console.log(typeof obj.f); // "number"
  142.  
  143. var a = [1, 2, 3];
  144. var b = a.map(n => n * 2);
  145. console.log(b.join(", ")); // 2, 4, 6
  146.  
  147. var a = [1, 2, 3];
  148. var b = a.map((n, i) => n * i);
  149. console.log(b.join(", ")); // 0, 2, 6
  150.  
  151. var a = [
  152. {first: "Joe", last: "Bloggs"},
  153. {first: "Albert", last: "Bloggs"},
  154. {first: "Mary", last: "Albright"}
  155. ];
  156. a = a.sort((a, b) => {
  157. var rv = a.last.localeCompare(b.last);
  158. if (rv === 0) {
  159. rv = a.first.localeCompare(b.first);
  160. }
  161. return rv;
  162. });
  163. console.log(JSON.stringify(a));
  164.  
  165. class Person {
  166. constructor(firstName, lastName) {
  167. this.firstName = firstName;
  168. this.lastName = lastName;
  169. }
  170.  
  171. getFullName() {
  172. return this.firstName + " " + this.lastName;
  173. }
  174. }
  175.  
  176. alert(typeof foo); // 'function', it's already available
  177. alert(typeof bar); // 'undefined'
  178. function foo () {}
  179. var bar = function () {};
  180. alert(typeof bar); // 'function'
  181.  
  182. function test () {}
  183. test = null;
  184.  
  185. (function(){
  186. var exports = {};
  187.  
  188. function privateUtil() {
  189. ...
  190. }
  191.  
  192. exports.publicUtil = function() {
  193. ...
  194. };
  195.  
  196. return exports;
  197. })();
  198.  
  199. functionTwo();
  200. function functionTwo() {
  201. }
  202.  
  203. functionOne(); --------------- var functionOne;
  204. | is actually | functionOne();
  205. var functionOne = function(){ | interpreted |-->
  206. }; | like | functionOne = function(){
  207. --------------- };
  208.  
  209. functionTwo(); --------------- function functionTwo() {
  210. | is actually | };
  211. function functionTwo() { | interpreted |-->
  212. } | like | functionTwo();
  213. ---------------
  214.  
  215. if (condition){
  216. function myfunction(){
  217. // some code
  218. }
  219. }
  220.  
  221. if (condition){
  222. var myfunction = function (){
  223. // some code
  224. }
  225. }
  226.  
  227. var MyNamespace = {}
  228. MyNamespace.foo= function() {
  229.  
  230. }
  231.  
  232. var MyNamespace {
  233. foo: function() {
  234. },
  235. ...
  236. }
  237.  
  238. var foo = 1;
  239. function bar() {
  240. if (!foo) {
  241. var foo = 10 }
  242. return foo; }
  243. bar() // 10
  244.  
  245. function f() {
  246. return a;
  247. function a() {return 1};
  248. var a = 4;
  249. function a() {return 2}}
  250. f()() // 2
  251.  
  252. function f() {
  253. return a;
  254. var a = 4;
  255. function a() {return 1};
  256. function a() {return 2}}
  257. f()() // 2
  258.  
  259. function f() {
  260. var a = 4;
  261. function a() {return 1};
  262. function a() {return 2};
  263. return a; }
  264. f() // 4
  265.  
  266. var a = 1;
  267. function b() {
  268. a = 10;
  269. return;
  270. function a() {}}
  271. b();
  272. a // 1
  273.  
  274. function abc(){}
  275.  
  276. var abc = function() {};
  277.  
  278. //this will work
  279. abc(param);
  280. function abc(){}
  281.  
  282. //this would fail
  283. abc(param);
  284. var abc = function() {}
  285.  
  286. {
  287. member:function() { /* How do I make "this.member" a named function? */
  288. }
  289. }
  290.  
  291. var ninja = {
  292. yell: function(n){
  293. return n > 0 ? ninja.yell(n-1) + "a" : "hiy";
  294. }
  295. };
  296. assert( ninja.yell(4) == "hiyaaaa", "A single object isn't too bad, either." );
  297.  
  298. var samurai = { yell: ninja.yell };
  299. var ninja = null;
  300.  
  301. try {
  302. samurai.yell(4);
  303. } catch(e){
  304. assert( false, "Uh, this isn't good! Where'd ninja.yell go?" );
  305. }
  306.  
  307. var ninja = {
  308. yell: function yell(n){
  309. return n > 0 ? yell(n-1) + "a" : "hiy";
  310. }
  311. };
  312. assert( ninja.yell(4) == "hiyaaaa", "Works as we would expect it to!" );
  313.  
  314. var samurai = { yell: ninja.yell };
  315. var ninja = {};
  316. assert( samurai.yell(4) == "hiyaaaa", "The method correctly calls itself." );
  317.  
  318. var objectOne = new functionOne();
  319. console.log(objectOne.__proto__); // prints "Object {}" because constructor is an anonymous function
  320.  
  321. var objectTwo = new functionTwo();
  322. console.log(objectTwo.__proto__); // prints "functionTwo {}" because constructor is a named function
  323.  
  324. var functionOne = function() {
  325. // Some code
  326. };
  327.  
  328. var one = new functionOne();
  329.  
  330. function functionTwo() {
  331. // Some code
  332. }
  333. two = new functionTwo();
  334.  
  335. var foo = function foo() {};
  336.  
  337. function foo() {};
  338.  
  339. function foo() {};
  340.  
  341. var foo = function foo() {};
  342.  
  343. var foo = undefined;
  344. foo = function foo() {};
  345.  
  346. global_Page = 10; var global_Page; « undefined
  347. « Integer literal, Number Type. ------------------- global_Page = 10; « Number
  348. global_Page = 'Yash'; | Interpreted | global_Page = 'Yash'; « String
  349. « String literal, String Type. « AS « global_Page = true; « Boolean
  350. var global_Page = true; | | global_Page = function (){ « function
  351. « Boolean Type ------------------- var local_functionblock; « undefined
  352. global_Page = function (){ local_functionblock = 777;« Number
  353. var local_functionblock = 777; };
  354. // Assigning function as a data.
  355. };
  356.  
  357. function Identifier_opt ( FormalParameterList_opt ) {
  358. FunctionBody | sequence of statements
  359.  
  360. « return; Default undefined
  361. « return 'some data';
  362. }
  363.  
  364. Scope with respect to function-block global.
  365. Scope with respect to page undefined | not available.
  366.  
  367. function globalAccess() { function globalAccess() {
  368. } ------------------- }
  369. globalAccess(); | | function globalAccess() { « Re-Defined / overridden.
  370. localAccess(); « Hoisted As « function localAccess() {
  371. function globalAccess() { | | }
  372. localAccess(); ------------------- localAccess(); « function accessed with in globalAccess() only.
  373. function localAccess() { }
  374. } globalAccess();
  375. } localAccess(); « ReferenceError as the function is not defined
  376.  
  377. 10; « literal
  378. (10); « Expression (10).toString() -> '10'
  379. var a;
  380. a = 10; « Expression var a.toString() -> '10'
  381. (function invoke() { « Expression Function
  382. console.log('Self Invoking'); (function () {
  383. }); }) () -> 'Self Invoking'
  384.  
  385. var f;
  386. f = function (){ « Expression var Function
  387. console.log('var Function'); f () -> 'var Function'
  388. };
  389.  
  390. (function selfExecuting(){
  391. console.log('IIFE - Immediately-Invoked Function Expression');
  392. }());
  393.  
  394. var anonymous = function (){
  395. console.log('anonymous function Expression');
  396. };
  397.  
  398. var namedExpression = function for_InternalUSE(fact){
  399. if(fact === 1){
  400. return 1;
  401. }
  402.  
  403. var localExpression = function(){
  404. console.log('Local to the parent Function Scope');
  405. };
  406. globalExpression = function(){
  407. console.log('creates a new global variable, then assigned this function.');
  408. };
  409.  
  410. //return; //undefined.
  411. return fact * for_InternalUSE( fact - 1);
  412. };
  413.  
  414. namedExpression();
  415. globalExpression();
  416.  
  417. var anonymous;
  418. var namedExpression;
  419. var globalExpression;
  420.  
  421. anonymous = function (){
  422. console.log('anonymous function Expression');
  423. };
  424.  
  425. namedExpression = function for_InternalUSE(fact){
  426. var localExpression;
  427.  
  428. if(fact === 1){
  429. return 1;
  430. }
  431. localExpression = function(){
  432. console.log('Local to the parent Function Scope');
  433. };
  434. globalExpression = function(){
  435. console.log('creates a new global variable, then assigned this function.');
  436. };
  437.  
  438. return fact * for_InternalUSE( fact - 1); // DEFAULT UNDEFINED.
  439. };
  440.  
  441. namedExpression(10);
  442. globalExpression();
  443.  
  444. function foo() {
  445. return 3;
  446. }
  447.  
  448. // Anonymous function expression
  449. var a = function() {
  450. return 3;
  451. }
  452.  
  453. // Named function expression
  454. var a = function foo() {
  455. return 3;
  456. }
  457.  
  458. // Self-invoking function expression
  459. (function foo() {
  460. alert("hello!");
  461. })();
  462.  
  463. [].forEach(function iterator() {});
  464.  
  465. 'use strict';
  466.  
  467. var a = function () {
  468. throw new Error();
  469. },
  470. b = function b() {
  471. throw new Error();
  472. },
  473. c = function d() {
  474. throw new Error();
  475. },
  476. e = {
  477. f: a,
  478. g: b,
  479. h: c,
  480. i: function () {
  481. throw new Error();
  482. },
  483. j: function j() {
  484. throw new Error();
  485. },
  486. k: function l() {
  487. throw new Error();
  488. }
  489. },
  490. m = (function () {
  491. return function () {
  492. throw new Error();
  493. };
  494. }()),
  495. n = (function () {
  496. return function n() {
  497. throw new Error();
  498. };
  499. }()),
  500. o = (function () {
  501. return function p() {
  502. throw new Error();
  503. };
  504. }());
  505.  
  506. console.log([a, b, c].concat(Object.keys(e).reduce(function (values, key) {
  507. return values.concat(e[key]);
  508. }, [])).concat([m, n, o]).reduce(function (logs, func) {
  509.  
  510. try {
  511. func();
  512. } catch (error) {
  513. return logs.concat('func.name: ' + func.name + 'n' +
  514. 'Trace:n' +
  515. error.stack);
  516. // Need to manually log the error object in Nitro.
  517. }
  518.  
  519. }, []).join('nn'));
  520.  
  521. func.name:
  522. Trace:
  523. Error
  524. at a (http://localhost:8000/test.js:4:11)
  525. at http://localhost:8000/test.js:47:9
  526. at Array.reduce (native)
  527. at http://localhost:8000/test.js:44:27
  528.  
  529. func.name: b
  530. Trace:
  531. Error
  532. at b (http://localhost:8000/test.js:7:15)
  533. at http://localhost:8000/test.js:47:9
  534. at Array.reduce (native)
  535. at http://localhost:8000/test.js:44:27
  536.  
  537. func.name: d
  538. Trace:
  539. Error
  540. at d (http://localhost:8000/test.js:10:15)
  541. at http://localhost:8000/test.js:47:9
  542. at Array.reduce (native)
  543. at http://localhost:8000/test.js:44:27
  544.  
  545. func.name:
  546. Trace:
  547. Error
  548. at a (http://localhost:8000/test.js:4:11)
  549. at http://localhost:8000/test.js:47:9
  550. at Array.reduce (native)
  551. at http://localhost:8000/test.js:44:27
  552.  
  553. func.name: b
  554. Trace:
  555. Error
  556. at b (http://localhost:8000/test.js:7:15)
  557. at http://localhost:8000/test.js:47:9
  558. at Array.reduce (native)
  559. at http://localhost:8000/test.js:44:27
  560.  
  561. func.name: d
  562. Trace:
  563. Error
  564. at d (http://localhost:8000/test.js:10:15)
  565. at http://localhost:8000/test.js:47:9
  566. at Array.reduce (native)
  567. at http://localhost:8000/test.js:44:27
  568.  
  569. func.name:
  570. Trace:
  571. Error
  572. at e.i (http://localhost:8000/test.js:17:19)
  573. at http://localhost:8000/test.js:47:9
  574. at Array.reduce (native)
  575. at http://localhost:8000/test.js:44:27
  576.  
  577. func.name: j
  578. Trace:
  579. Error
  580. at j (http://localhost:8000/test.js:20:19)
  581. at http://localhost:8000/test.js:47:9
  582. at Array.reduce (native)
  583. at http://localhost:8000/test.js:44:27
  584.  
  585. func.name: l
  586. Trace:
  587. Error
  588. at l (http://localhost:8000/test.js:23:19)
  589. at http://localhost:8000/test.js:47:9
  590. at Array.reduce (native)
  591. at http://localhost:8000/test.js:44:27
  592.  
  593. func.name:
  594. Trace:
  595. Error
  596. at http://localhost:8000/test.js:28:19
  597. at http://localhost:8000/test.js:47:9
  598. at Array.reduce (native)
  599. at http://localhost:8000/test.js:44:27
  600.  
  601. func.name: n
  602. Trace:
  603. Error
  604. at n (http://localhost:8000/test.js:33:19)
  605. at http://localhost:8000/test.js:47:9
  606. at Array.reduce (native)
  607. at http://localhost:8000/test.js:44:27
  608.  
  609. func.name: p
  610. Trace:
  611. Error
  612. at p (http://localhost:8000/test.js:38:19)
  613. at http://localhost:8000/test.js:47:9
  614. at Array.reduce (native)
  615. at http://localhost:8000/test.js:44:27 test.js:42
  616.  
  617. func.name:
  618. Trace:
  619. a@http://localhost:8000/test.js:4:5
  620. @http://localhost:8000/test.js:47:9
  621. @http://localhost:8000/test.js:54:1
  622.  
  623.  
  624. func.name: b
  625. Trace:
  626. b@http://localhost:8000/test.js:7:9
  627. @http://localhost:8000/test.js:47:9
  628. @http://localhost:8000/test.js:54:1
  629.  
  630.  
  631. func.name: d
  632. Trace:
  633. d@http://localhost:8000/test.js:10:9
  634. @http://localhost:8000/test.js:47:9
  635. @http://localhost:8000/test.js:54:1
  636.  
  637.  
  638. func.name:
  639. Trace:
  640. a@http://localhost:8000/test.js:4:5
  641. @http://localhost:8000/test.js:47:9
  642. @http://localhost:8000/test.js:54:1
  643.  
  644.  
  645. func.name: b
  646. Trace:
  647. b@http://localhost:8000/test.js:7:9
  648. @http://localhost:8000/test.js:47:9
  649. @http://localhost:8000/test.js:54:1
  650.  
  651.  
  652. func.name: d
  653. Trace:
  654. d@http://localhost:8000/test.js:10:9
  655. @http://localhost:8000/test.js:47:9
  656. @http://localhost:8000/test.js:54:1
  657.  
  658.  
  659. func.name:
  660. Trace:
  661. e.i@http://localhost:8000/test.js:17:13
  662. @http://localhost:8000/test.js:47:9
  663. @http://localhost:8000/test.js:54:1
  664.  
  665.  
  666. func.name: j
  667. Trace:
  668. j@http://localhost:8000/test.js:20:13
  669. @http://localhost:8000/test.js:47:9
  670. @http://localhost:8000/test.js:54:1
  671.  
  672.  
  673. func.name: l
  674. Trace:
  675. l@http://localhost:8000/test.js:23:13
  676. @http://localhost:8000/test.js:47:9
  677. @http://localhost:8000/test.js:54:1
  678.  
  679.  
  680. func.name:
  681. Trace:
  682. m</<@http://localhost:8000/test.js:28:13
  683. @http://localhost:8000/test.js:47:9
  684. @http://localhost:8000/test.js:54:1
  685.  
  686.  
  687. func.name: n
  688. Trace:
  689. n@http://localhost:8000/test.js:33:13
  690. @http://localhost:8000/test.js:47:9
  691. @http://localhost:8000/test.js:54:1
  692.  
  693.  
  694. func.name: p
  695. Trace:
  696. p@http://localhost:8000/test.js:38:13
  697. @http://localhost:8000/test.js:47:9
  698. @http://localhost:8000/test.js:54:1
  699.  
  700. func.name: undefined
  701. Trace:
  702. Error
  703. at a (http://localhost:8000/test.js:4:5)
  704. at Anonymous function (http://localhost:8000/test.js:47:9)
  705. at Global code (http://localhost:8000/test.js:42:1)
  706.  
  707.  
  708. func.name: undefined
  709. Trace:
  710. Error
  711. at b (http://localhost:8000/test.js:7:9)
  712. at Anonymous function (http://localhost:8000/test.js:47:9)
  713. at Global code (http://localhost:8000/test.js:42:1)
  714.  
  715.  
  716. func.name: undefined
  717. Trace:
  718. Error
  719. at d (http://localhost:8000/test.js:10:9)
  720. at Anonymous function (http://localhost:8000/test.js:47:9)
  721. at Global code (http://localhost:8000/test.js:42:1)
  722.  
  723.  
  724. func.name: undefined
  725. Trace:
  726. Error
  727. at a (http://localhost:8000/test.js:4:5)
  728. at Anonymous function (http://localhost:8000/test.js:47:9)
  729. at Global code (http://localhost:8000/test.js:42:1)
  730.  
  731.  
  732. func.name: undefined
  733. Trace:
  734. Error
  735. at b (http://localhost:8000/test.js:7:9)
  736. at Anonymous function (http://localhost:8000/test.js:47:9)
  737. at Global code (http://localhost:8000/test.js:42:1)
  738.  
  739.  
  740. func.name: undefined
  741. Trace:
  742. Error
  743. at d (http://localhost:8000/test.js:10:9)
  744. at Anonymous function (http://localhost:8000/test.js:47:9)
  745. at Global code (http://localhost:8000/test.js:42:1)
  746.  
  747.  
  748. func.name: undefined
  749. Trace:
  750. Error
  751. at e.i (http://localhost:8000/test.js:17:13)
  752. at Anonymous function (http://localhost:8000/test.js:47:9)
  753. at Global code (http://localhost:8000/test.js:42:1)
  754.  
  755.  
  756. func.name: undefined
  757. Trace:
  758. Error
  759. at j (http://localhost:8000/test.js:20:13)
  760. at Anonymous function (http://localhost:8000/test.js:47:9)
  761. at Global code (http://localhost:8000/test.js:42:1)
  762.  
  763.  
  764. func.name: undefined
  765. Trace:
  766. Error
  767. at l (http://localhost:8000/test.js:23:13)
  768. at Anonymous function (http://localhost:8000/test.js:47:9)
  769. at Global code (http://localhost:8000/test.js:42:1)
  770.  
  771.  
  772. func.name: undefined
  773. Trace:
  774. Error
  775. at Anonymous function (http://localhost:8000/test.js:28:13)
  776. at Anonymous function (http://localhost:8000/test.js:47:9)
  777. at Global code (http://localhost:8000/test.js:42:1)
  778.  
  779.  
  780. func.name: undefined
  781. Trace:
  782. Error
  783. at n (http://localhost:8000/test.js:33:13)
  784. at Anonymous function (http://localhost:8000/test.js:47:9)
  785. at Global code (http://localhost:8000/test.js:42:1)
  786.  
  787.  
  788. func.name: undefined
  789. Trace:
  790. Error
  791. at p (http://localhost:8000/test.js:38:13)
  792. at Anonymous function (http://localhost:8000/test.js:47:9)
  793. at Global code (http://localhost:8000/test.js:42:1)
  794.  
  795. func.name:
  796. Trace:
  797. a@http://localhost:8000/test.js:4:22
  798. http://localhost:8000/test.js:47:13
  799. reduce@[native code]
  800. global code@http://localhost:8000/test.js:44:33
  801.  
  802. func.name: b
  803. Trace:
  804. b@http://localhost:8000/test.js:7:26
  805. http://localhost:8000/test.js:47:13
  806. reduce@[native code]
  807. global code@http://localhost:8000/test.js:44:33
  808.  
  809. func.name: d
  810. Trace:
  811. d@http://localhost:8000/test.js:10:26
  812. http://localhost:8000/test.js:47:13
  813. reduce@[native code]
  814. global code@http://localhost:8000/test.js:44:33
  815.  
  816. func.name:
  817. Trace:
  818. a@http://localhost:8000/test.js:4:22
  819. http://localhost:8000/test.js:47:13
  820. reduce@[native code]
  821. global code@http://localhost:8000/test.js:44:33
  822.  
  823. func.name: b
  824. Trace:
  825. b@http://localhost:8000/test.js:7:26
  826. http://localhost:8000/test.js:47:13
  827. reduce@[native code]
  828. global code@http://localhost:8000/test.js:44:33
  829.  
  830. func.name: d
  831. Trace:
  832. d@http://localhost:8000/test.js:10:26
  833. http://localhost:8000/test.js:47:13
  834. reduce@[native code]
  835. global code@http://localhost:8000/test.js:44:33
  836.  
  837. func.name:
  838. Trace:
  839. i@http://localhost:8000/test.js:17:30
  840. http://localhost:8000/test.js:47:13
  841. reduce@[native code]
  842. global code@http://localhost:8000/test.js:44:33
  843.  
  844. func.name: j
  845. Trace:
  846. j@http://localhost:8000/test.js:20:30
  847. http://localhost:8000/test.js:47:13
  848. reduce@[native code]
  849. global code@http://localhost:8000/test.js:44:33
  850.  
  851. func.name: l
  852. Trace:
  853. l@http://localhost:8000/test.js:23:30
  854. http://localhost:8000/test.js:47:13
  855. reduce@[native code]
  856. global code@http://localhost:8000/test.js:44:33
  857.  
  858. func.name:
  859. Trace:
  860. http://localhost:8000/test.js:28:30
  861. http://localhost:8000/test.js:47:13
  862. reduce@[native code]
  863. global code@http://localhost:8000/test.js:44:33
  864.  
  865. func.name: n
  866. Trace:
  867. n@http://localhost:8000/test.js:33:30
  868. http://localhost:8000/test.js:47:13
  869. reduce@[native code]
  870. global code@http://localhost:8000/test.js:44:33
  871.  
  872. func.name: p
  873. Trace:
  874. p@http://localhost:8000/test.js:38:30
  875. http://localhost:8000/test.js:47:13
  876. reduce@[native code]
  877. global code@http://localhost:8000/test.js:44:33
  878.  
  879. function outerFunction() {
  880. function foo() {
  881. return 1;
  882. }
  883. return foo();
  884. function foo() {
  885. return 2;
  886. }
  887. }
  888. alert(outerFunction()); // Displays 2
  889.  
  890. function foo() { // The first function declaration is moved to top
  891. return 1;
  892. }
  893. function foo() { // The second function declaration is moved to top
  894. return 2;
  895. }
  896. function outerFunction() {
  897. return foo();
  898. }
  899. alert(outerFunction()); //So executing from top to bottom,
  900. //the last foo() returns 2 which gets displayed
  901.  
  902. function outerFunction() {
  903. var foo = function() {
  904. return 1;
  905. }
  906. return foo();
  907. var foo = function() {
  908. return 2;
  909. }
  910. }
  911. alert(outerFunction()); // Displays 1
  912.  
  913. function outerFunction() {
  914. var foo = undefined;
  915. var foo = undefined;
  916.  
  917. foo = function() {
  918. return 1;
  919. };
  920. return foo ();
  921. foo = function() { // This function expression is not reachable
  922. return 2;
  923. };
  924. }
  925. alert(outerFunction()); // Displays 1
  926.  
  927. if (test) {
  928. function x() { doSomething(); }
  929. }
  930.  
  931. var today = function today() {return new Date()}
  932.  
  933. functionOne();
  934. var functionOne = function() {
  935. // Some code
  936. };
  937.  
  938. functionOne();
  939. function functionOne() {
  940. // Some code
  941. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement