摘要: 这要从对象,实例和原型三者关系说起,如果学过面向对象的语言或者知道面向对象,那么一个对象可以创建一个实例,这应该没有问题,这是前提,现在开始说重点。首先js中对象(函数(function)也是对象),可以访问到原型(prototype),然后通过对象得到的原型(prototype)中也会有一个给对象的指针(即constructor)例如 :function Person(){};var pro = Person.prototype;//得到对象的原型 var obj = pro.constructor ; // 这样可以得到Person对象。对象创建对象的实例就不多说了 var p = new 阅读全文
posted @ 2012-12-27 11:20 家有小河马 阅读(203) 评论(0) 推荐(0)
摘要: 转载群里大牛吐槽:----请大家给提点意见 假如说 <div style="background:rgb(${r},${g},${b});width:100px;height:100px;"></div> <input value="${r}" type="text"/> <input value="${g}" /> <input value="${b}" />这样的一个模版 我想要区分绑定attribute和property 大家觉得 阅读全文
posted @ 2012-08-29 09:13 家有小河马 阅读(134) 评论(0) 推荐(0)
摘要: ECMAScript5将严格模式(strict mode)引入了Javascript中,目的是允许开发人员能够选择“更好”的Javascript版本,这个版本能用不同的方式处理那些普遍而又臭名昭著的错误。一开始的时候,我对该模式抱着怀疑的态度,因为当时在只有一款浏览器(Firefox)支持严格模式。时至今日,所有的主流浏览器的最新版本——包括IE10与Opera12——都支持严格模式。使用严格模式的时机已经成熟了。它带来了什么?严格模式给Javascript的运行方式带来了许多不同,我将它们分为了两类:明显的(obvious),以及微妙的(subtle)。那些微妙的改变是为了解决微妙的问题,我 阅读全文
posted @ 2012-08-24 16:38 家有小河马 阅读(158) 评论(0) 推荐(0)
摘要: 原文链接:http://www.codeproject.com/Articles/182416/A-Collection-of-JavaScript-GotchasIntroductionThis article is an introduction to the weird side of JavaScript, and it definitely has a weird side! Software developers who usually write code in another language will find a lot of intriguing "featur 阅读全文
posted @ 2012-07-28 22:48 家有小河马 阅读(170) 评论(0) 推荐(0)
摘要: 原文出处:http://davidshariff.com/blog/what-is-the-execution-context-in-javascript/In this post I will take an in-depth look at one of the most fundamental parts of JavaScript, theExecution Context. By the end of this post, you should have a clearer understanding about what the interpreter is trying to d 阅读全文
posted @ 2012-07-26 14:32 家有小河马 阅读(350) 评论(0) 推荐(0)
摘要: varf=function(){ return1;}console.log(f());//1functionf(){ return2;}console.log(f());//1这是为什么呢?runtime的时候,var会重新内建,function在编译时内建。相当于vara=2;vara=1;console.log(a);function定义的会被先建立。var的在运行的时候建立。所以每次执行的时候,var的把之前建立的给覆盖掉了。或者可以这样描述function的相当于静态的var的是动态的var在执行的时候建立 阅读全文
posted @ 2012-07-26 13:22 家有小河马 阅读(166) 评论(0) 推荐(0)
摘要: vara=0;varb=3;functioncom(){ a=1; returnfunction(){ b=a+a; }} com();console.log(a); //1console.log(b); //3------------------------------vara=0;varb=0;functioncom(){ a=1; c=5; returnfunction(c){ b=a+c; }} com()();console.log(a); //1console.log(b); //NaNconsole.log(c); //5 阅读全文
posted @ 2012-07-26 10:15 家有小河马 阅读(137) 评论(0) 推荐(0)
摘要: ss=Object.beget(hi);ss=hi;-------------------------hi = {a:1};ss=Object.beget(hi);alert(ss.a);//1ss.a = 2;alert(ss.a);//2alert(hi.a);//1delete ss.aalert(ss.a);//1这个就是所谓的原型了 阅读全文
posted @ 2012-07-18 17:08 家有小河马 阅读(144) 评论(0) 推荐(0)
摘要: 今天群里的大大们强势吐槽:字面量就是用最直观的方式创建一个对象其实是很常见的东西,以数组为例:var arr = [1,2,3]就是字面量形式,var arr = new Array(1,2,3)就是对象形式JS里面貌似 BooleanLiteral NumberLiteral StringLiteral NullLiteral 属于LiteralObjectLiteral 和ArrayLiteral 貌似不算Literal按照es5的描述,还有regexp literalsliteral就是前面提到的“字面量”,也见过翻译成“直接量”“字面值”的es5里的这些arrayliteral和obj 阅读全文
posted @ 2012-07-18 17:06 家有小河马 阅读(1356) 评论(0) 推荐(1)