`
peryt
  • 浏览: 55277 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery

the last hash in param in a function call can omit {}

阅读更多

there is one note about the element order in hashes:


Ruby 1.9 actually guarantees that hashes keep their elements in the same order entered, but it would be unwise ever to count on a particular ordering. 

 

==================================================

 

let's see this method:

 

stylesheet_link_tag 'blueprint/screen', :media => 'screen'

 

you will find the last param is a hash, but why there is no {} around this hash?

 

the reason is this:

 

when the hash is the last argument in a function call, the {} is optional, the following two lines are equivalent:

 

 

stylesheet_link_tag 'blueprint/screen', { :media => 'screen' }
stylesheet_link_tag 'blueprint/screen', :media => 'screen'

 

note this only apply to a function call, not a function definition.

 

by the way, the html generated by the above code is:

 


<link href="/stylesheets/blueprint/screen.css" media="screen" rel="stylesheet"
type="text/css" />
<link href="/stylesheets/blueprint/print.css" media="print" rel="stylesheet"
type="text/css" />
0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics