开发者

Please explain this example script from the LinkedIn developer API

I'm just getting started with the LinkedIn JavaScript API and right away I noticed a pattern that I am not familiar with:

<script src="http://platform.linkedin.com/in.js">
    api_key: dfghyu8v2tg
</script>

I have two questions:

  1. What is the type and scope of the api_key object?
  2. Does the referred script have special access to the content in the script tag because its the src of the tag?

Edit: According to Douglas Crockford (emphasis mine):

The src attribute is optional. If it is present, then its value is a url which identifies a .js file. The loading and processing of the page pauses while the browser fetches, compiles, and executes the file. The content between the <script src="url"> and the </script> should be blank开发者_运维百科.

If the src attribute is not present, then the content text between the <script> and the </script> is compiled and executed.

It seems to me that the LinkedIn example does not meet these requirements.


What is the type and scope of the api_key object?

If you treat this as JavaScript then…

It is a label followed by a (presumably) undefined variable, which will throw a reference error.

Does the referred script have special access to the content in the script tag because its the src of the tag?

No. The content of the script element is the fallback for when src is not supported. It is being abused as a hack to include extra data. A glance at the script (in the src) suggests it loops over all the <script> elements it can find and checks their innerHTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜