<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>js on adolsai's echo</title><link>https://adolsai.com/tag/js/</link><description>Recent content in js on adolsai's echo</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Wed, 19 Mar 2014 08:52:18 +0800</lastBuildDate><atom:link href="https://adolsai.com/tag/js/index.xml" rel="self" type="application/rss+xml"/><item><title>javascript learning notes——function</title><link>https://adolsai.com/archives/43.html</link><pubDate>Wed, 12 Mar 2014 00:13:00 +0800</pubDate><guid>https://adolsai.com/archives/43.html</guid><description>&lt;p&gt;&lt;strong&gt;函数&lt;/strong&gt;：一次定义，多次执行。js的函数调用还有一个特性，每次调用都会拥有另一个值——本次调用的this值（上下文/context）。函数可以作为对象的一个属性，称为对象的方法。当通过对象调用函数时，该对象就是此次调用的上下文。&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;//在定义的时候递归&#10;var f = function fact(x) {if (x&amp;lt;=1) return 1; else return x*fact(x-1);};&#10;//作为参数传递&#10;data.sort(function(a,b){return a-b;});&#10;//定义后立即使用&#10;var tensquared = (function(x){return x*x}(10));&#10;&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>js debug function</title><link>https://adolsai.com/archives/8.html</link><pubDate>Wed, 26 Feb 2014 17:30:00 +0800</pubDate><guid>https://adolsai.com/archives/8.html</guid><description>&lt;pre&gt;&lt;code&gt;//在document中的一个指定的区域输出调试信息&#10;//如果document不存在这样的一个区域，则创建一个&#10;function debug(msg){&#10; //通过查看HTML元素id属性来查找文档的调试部分&#10; var log = document.getElementById("debuglog");&#10;&#10; if (!log){&#10; log = document.createElement("div");&#10; log.id = "debuglog";&#10; log.innerHTML = "&amp;lt;h1&amp;gt;Debug Log&amp;lt;/h1&amp;gt;";&#10; document.body.appendChild(log);&#10; }&#10; //将消息包装在&amp;lt;pre&amp;gt;中，并添加到log中&#10; var pre = document.createElement("pre");&#10; var text = document.createTextNode(msg);&#10; pre.appendChild(text);&#10; log.appendChild(pre);&#10;}&#10;&lt;/code&gt;&lt;/pre&gt;</description></item></channel></rss>