RequireJs入門

the relationship between ''require" & "requirejs"

it is the same!
you can try

if(require===requirejs){
      alert(true);
    }```
it can be tested!

## the relationship between 'require' $ 'define'

require(['a'], function(a) {
// some code
});
//load this 'a' module ,and run the function

define(['b','c','d','e'], function() {
//some code
});
// If you need a XXX, then load these other things first, then return the result of this function.

a define *might never be called*.
As long as there is only one define , it will register that module as available under that filename. However, define modules are only loaded once a require function asks for each of them.

## './'  & '../' &'paths'
./ means the root of your directory and anything appended to ./ is the module in your same directory.
./module is useful because you don't have to set paths in your config.paths property.
paths is like a absolute path configured in the project , you can always use require('module') in your code as you have already configure it in configure.js in paths form
../ means the root of the project **which is the baseUrl location!!**

root
dir
file1
file2
dir2
file1
file2


If you are in root/dir . refers to root/dir so ./file1 refers to /root/dir/file1
.. refers to root so ../file1 doesn't exist (root/file1)

.  represent the current working directory
.. represent the parent directory of the current working directory.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容