Más contenido relacionado Es5111. writable = false obj={ class:'Menu' } obj.class='Bird‘ =>obj.class == ‘Menu’ 16. Закрытие объекта varuser={ name:"Вася", /* ... */ } Object.preventExtensions(user) user.a=5// Нельзя добавлять свойства Object.seal(user) deleteuser.name// Нельзя удалять свойства Object.freeze(user) user.name='Петя'// Нельзя менять свойства 17. Наследование animal={ canWalk:true } rabbit=Object.create(animal,{ canRun:{ value:true } }) alert(rabbit.canWalk)// true Object.getPrototypeOf(rabbit) == animal // true 19. Геттеры и Сеттеры user=Object.defineProperty({},"fullName",{ get:function(){ returnthis.firstName+' '+this.lastName }, set:function(value){ vars=value.trim().split(/+/,2) this.firstName=s[0]; this.lastName=s[1] } }) user.fullName="Вася Пупкин" alert(user.lastName)// Пупкин 20. Геттеры и Сеттеры varuser={ getfullName(){ returnthis.firstName+' '+this.lastName }, setfullName(value){ vars=value.trim().split(/+/,2) this.firstName=s[0]; this.lastName=s[1] } } user.fullName="Вася Пупкин" alert(user.lastName)// Пупкин 23. JSON – любые объекты functionRoom(number){ this.toJSON=function(){ returnnumber } } event={ title:"Conference", date:newDate(), room:newRoom(22) } JSON.stringify(event) {"title":"Conference","date":"2011-02-15T09:12:06.836Z","room":22} 24. JSON – любые объекты functionRoom(number){ this.toJSON=function(){ returnnumber } } event={ title:"Conference", date:newDate(), Date.prototype.toJSON room:newRoom(22) } JSON.stringify(event) {"title":"Conference","date":"2011-02-15T09:12:06.836Z","room":22} 25. JSON.stringify(str, whitelist) event={ title:"Conference", date:newDate(), domElement:document.body } JSON.stringify(event) => TypeError: Converting circular structure to JSON JSON.stringify(event,["title","date"]) => {"title":"Conference","date":"2011-02-15T09:44:13.419Z"} 26. JSON.stringify(str, replacer) event={ title:"Conference", date:newDate(), domElement:document.body } JSON.stringify(event,function(key,value){ returnvalue.nodeName?undefined:value }) => {"title":"Conference","date":"2011-02-15T09:44:13.419Z"} 32. bind(this, args) functionButton(elem){ this.say=function(phrase){ alert(phrase) } elem.onclick=function(event,phrase){ this.say(phrase) }.bind(this,'Hi') } @see http://www.prototypejs.org/api/function/bind 36. use strict alert(010)// SyntaxError (octal literals deprecated) a=5// ReferenceError (undeclared a) obj.notWritable=...// TypeError deleteobj.notConfigurable// TypeError eval("var a = 5") alert(a)// ReferenceError (undeclared a) arguments.callee// TypeError arguments.caller// TypeError (function(){ alert(this)// undefined вместо window })() with(..)// SyntaxError, 'with' statement 37. Функции,которые давно ждали Object.keys(obj) "String".trim() Array.isArray(arr) [...].indexOf/lastIndexOf [...].forEach [...].map [...].filter [...].reduce/reduceRight // ... @seehttp://kangax.github.com/es5-compat-table/ 38. The future is now ? ECMAScript 5 compatibility table ES5-shim 40. It’s all real __noSuchMethod__Proxy.create letblock_scoped="yay!" constREALLY="srsly" #(x) { x * x } ifx>zreturn"без скобок" moduleIter="@std:Iteration" return[i*iforiinrange(n)] functionprintf(format,...args)ek_scoped= "yay!" consEALLY= "srsly"