Friday, 15 June 2012

javascript - Calling function of non amd in requirejs -


I & amp; have read; I want to understand this concept more clearly, so I have made my two files

lorem.js :

  var lorem = { }; Lorem.fun1 = function () {console.log ('aaa'); };  

ipsum.js :

  var ipsum = {}; Ipsum.color = 'a'; Ipsum.fun1 = function () {lorem.fun1 (); };  

Depending on Ipsum Lorame I have done something like this in the Shim configuration:

  // file name: main.js // Require.js us The shortcut allows the nickname to be configured // The usage will be more clear in this tutorial. Need help .config ({baseUrl: 'js', path: {/ * jquery: [//' https://ajax.googleapis.com/ Ajax / libs / jquery / 2.1.3 / jquery.min ',' Libs / Jquery / jquery '], backbone: [' Libs / Backbone / Backbone '], underscore: [' Libs / underscore / underscores'], * / Ipsum: 'Non Amed / Ipsum', Loram: 'Non Amed / Lore '}, Shim: [/ Jquery: {export:' jQuery '}, underscore: {export:' _ '}, spinal cord: {deps: [' jquery ',' underscores'], export: 'backbone' }, * / Ipsum: {Deps: ['Lorem'], export: 'epsom'}}}); Expected (['ipsum'], function (Ipsum) {console.log (Ipsum);});  

However, in console.log (Ipsum) print undefined console. What am i doing wrong

Your mistake is in Shim configuration.

  ipsum: {deps: ['lorem'], should be exported: 'epsom'}  

  Ipsum: {deps: focus on changing case with '' Ipsum 'from ' ipsum '.  .  should be a global variable in  ipsum  in  ipsum.js . 

In Javascript, variable names are case-sensitive, so Ipsum and Ipsum are different because you have Ipsum , only < Code> ipsum , it was printed undefined .


No comments:

Post a Comment