<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"><id>tag:blogger.com,1999:blog-34454975</id><updated>2013-05-18T00:58:20.798+02:00</updated><category term="VBScript" /><category term="cipher" /><category term="Visual Studio" /><category term="enough" /><category term="protocol" /><category term="solution" /><category term="super" /><category term="literal" /><category term="bug" /><category term="140" /><category term="crystal" /><category term="ArrayObject" /><category term="CommonJS" /><category term="String" /><category term="on" /><category term="conversion" /><category term="new" /><category term="revisited" /><category term="proposal" /><category term="hghlight" /><category term="ElseIf" /><category term="require" /><category term="getElementsByClassName" /><category term="Apple" /><category term="upgrade" /><category term="preciseTime" /><category term="JavaScript.XML" /><category term="Code" /><category term="make" /><category term="detection" /><category term="with" /><category term="N510" /><category term="not" /><category term="thoughts" /><category term="FatalError" /><category term="SPL" /><category term="Yahtzee" /><category term="defects" /><category term="mini" /><category term="Laptop" /><category term="write" /><category term="evil" /><category term="Apache" /><category term="xhtml" /><category term="setImmediate" /><category term="closures" /><category term="minifier" /><category term="friendly" /><category term="opera" /><category term="sort" /><category term="scripting" /><category term="recycle" /><category term="gif" /><category term="distributed" /><category term="type" /><category term="Shaders" /><category term="XSL" /><category term="Fart" /><category term="Hunspell" /><category term="CSS" /><category term="talk" /><category term="Unit Test" /><category term="in" /><category term="delirium" /><category term="Christmas" /><category term="leak" /><category term="hybrid" /><category term="effect" /><category term="exposed" /><category term="trim" /><category term="yal.js" /><category term="experiment" /><category term="OSX" /><category term="UK" /><category term="writable" /><category term="Elsewhere" /><category term="Dash" /><category term="anonymous" /><category term="bytes" /><category term="JavaScirpt" /><category term="Array" /><category term="LAB.js" /><category term="JSON.hpack" /><category term="obtrusive" /><category term="JSONH" /><category term="2.0" /><category term="power" /><category term="lightweight" /><category term="design" /><category term="Internet Explorer" /><category term="ubuntu" /><category term="CDN" /><category term="notification" /><category term="convertion" /><category term="Sizzle" /><category term="prevent" /><category term="compiler" /><category term="BJSpell" /><category term="this" /><category term="Aptana" /><category term="Internet Epxlorer" /><category term="Microsoft" /><category term="best" /><category term="ES6" /><category term="sessionStorage" /><category term="W3C" /><category term="debugger" /><category term="flight" /><category term="status" /><category term="serialization" /><category term="jQuery UI" /><category term="SWF" /><category term="demo" /><category term="FX" /><category term="Harmony" /><category term="PAMPA-J" /><category term="define" /><category term="ctypes" /><category term="node" /><category term="response" /><category term="indexOf" /><category term="frameworks" /><category term="Chrome" /><category term="markdown" /><category term="plugin" /><category term="Framework" /><category term="defineHybridProperty" /><category term="compressed" /><category term="new year" /><category term="Batch" /><category term="transitions" /><category term="Surface" /><category term="transformer" /><category term="_super" /><category term="toISOString" /><category term="touch" /><category term="automator" /><category term="focus" /><category term="Object" /><category term="gesture" /><category term="common" /><category term="cross" /><category term="tricks" /><category term="falsy" /><category term="JXON" /><category term="arrow" /><category term="IE6" /><category term="wru" /><category term="silverlight" /><category term="check" /><category term="constant" /><category term="fromCharCode" /><category term="area" /><category term="ASCII" /><category term="engine" /><category term="performances" /><category term="files" /><category term="size" /><category term="Max Execution Stack" /><category term="button" /><category term="ball" /><category term="readyState" /><category term="create" /><category term="Roundtable" /><category term="properties" /><category term="private" /><category term="JSLint" /><category term="queue" /><category term="Options" /><category term="PHP" /><category term="meta" /><category term="Mousetrap" /><category term="CoffeeShit" /><category term="interaction" /><category term="unload" /><category term="Ext JS" /><category term="CSS3" /><category term="Ruby" /><category term="getPrototypeOf" /><category term="log" /><category term="callee" /><category term="devpro.it" /><category term="outerHTML" /><category term="Frame" /><category term="Samsung" /><category term="jSmile" /><category term="intenret" /><category term="Sandbox" /><category term="webapp" /><category term="expando" /><category term="assignment" /><category term="decimal" /><category term="WorkerLocation" /><category term="Informations" /><category term="Pascal" /><category term="btoa" /><category term="Unite" /><category term="mobile" /><category term="natural" /><category term="documentation" /><category term="html5" /><category term="characters" /><category term="Image" /><category term="C" /><category term="good" /><category term="imrovements" /><category term="relation" /><category term="method" /><category term="WebKit" /><category term="grant" /><category term="apply" /><category term="getElementsByTagName" /><category term="library" /><category term="convention" /><category term="Sprotector" /><category term="ES3" /><category term="IE10" /><category term="pointers" /><category term="side" /><category term="base64" /><category term="Flash" /><category term="devices" /><category term="Trends" /><category term="save as" /><category term="standard" /><category term="Rhino" /><category term="function" /><category term="List" /><category term="performance" /><category term="isFunction" /><category term="injection" /><category term="EventEmitter" /><category term="swine flu" /><category term="limit" /><category term="banner" /><category term="safari" /><category term="broken" /><category term="Builder" /><category term="defineProperty" /><category term="defineProperties" /><category term="jQuery" /><category term="merits" /><category term="bad" /><category term="lightning" /><category term="attribute" /><category term="overload" /><category term="isCallable" /><category term="driven" /><category term="VS9" /><category term="Revolution" /><category term="scope" /><category term="MDC" /><category term="onload" /><category term="toolbar" /><category term="parody" /><category term="XML" /><category term="unpacked" /><category term="improvement" /><category term="dataset" /><category term="language" /><category term="Ten Grand" /><category term="advanced" /><category term="slickspeed" /><category term="drinking" /><category term="filter" /><category term="correct" /><category term="Else" /><category term="javascript 2" /><category term="Listener" /><category term="style" /><category term="var_export" /><category term="Map" /><category term="emulation" /><category term="for in" /><category term="Observer" /><category term="global" /><category term="region" /><category term="polyfills" /><category term="tuscany" /><category term="software" /><category term="errors" /><category term="ie7" /><category term="Multiton" /><category term="begetObject" /><category term="ES5" /><category term="getPropertyNames" /><category term="bit.ly" /><category term="Levenshtein" /><category term="Io" /><category term="postable" /><category term="compressor" /><category term="prototype" /><category term="recursion" /><category term="implicit cast" /><category term="node.js" /><category term="Twitter" /><category term="unobtrusive" /><category term="GWT" /><category term="mistake" /><category term="technologies" /><category term="inline" /><category term="YAGNI" /><category term="connection" /><category term="restaurant" /><category term="2011" /><category term="outline" /><category term="Date" /><category term="getAttribute" /><category term="fast" /><category term="UPDATE" /><category term="benchmark" /><category term="gzip" /><category term="Formaldehyde" /><category term="ambiguity" /><category term="User" /><category term="TechHub" /><category term="Jam" /><category term="console" /><category term="js-ctypes" /><category term="download" /><category term="localStorage" /><category term="TaskSpeed" /><category term="8601" /><category term="CPU" /><category term="browser" /><category term="EventListener" /><category term="monitor" /><category term="class" /><category term="Macro" /><category term="script" /><category term="Object.create" /><category term="background" /><category term="debug_backtrace" /><category term="file" /><category term="JavaScriptCore" /><category term="default" /><category term="Application" /><category term="tesla" /><category term="fatal" /><category term="debug" /><category term="use strict" /><category term="crash" /><category term="batman" /><category term="unserialize" /><category term="gzipped" /><category term="process" /><category term="patterns" /><category term="HTMLCollection" /><category term="stream" /><category term="essential" /><category term="random" /><category term="chain" /><category term="broadband" /><category term="reset" /><category term="PC Pro" /><category term="translator" /><category term="2010" /><category term="instance" /><category term="YUI" /><category term="API" /><category term="removeAttribute" /><category term="null" /><category term="constructor" /><category term="enumerable" /><category term="C#" /><category term="source" /><category term="Algorithm" /><category term="tests" /><category term="blogger" /><category term="TreePanel" /><category term="RegExp" /><category term="Mootools" /><category term="fixed" /><category term="call" /><category term="Agent" /><category term="shared" /><category term="basis" /><category term="upload" /><category term="runtime" /><category term="Singleton" /><category term="structure" /><category term="features" /><category term="vice-versa" /><category term="yuno" /><category term="pattern" /><category term="VBClass" /><category term="maps" /><category term="Dart" /><category term="StringBuilder" /><category term="way" /><category term="valueOf" /><category term="scree" /><category term="avoid" /><category term="resize" /><category term="JSObject" /><category term="live" /><category term="arguments" /><category term="development" /><category term="privileged" /><category term="watch" /><category term="Ajaxian" /><category term="floor" /><category term="Berlin" /><category term="self" /><category term="Math" /><category term="events" /><category term="parsing" /><category term="Windows" /><category term="resolution" /><category term="partial" /><category term="buzz" /><category term="conflicts" /><category term="module" /><category term="inheritance" /><category term="Relator" /><category term="JsonTV" /><category term="O3D" /><category term="bookmarklet" /><category term="stand alone" /><category term="spam" /><category term="WebSQL" /><category term="Expressions" /><category term="jsc" /><category term="prototypal" /><category term="deflate" /><category term="WebReflection" /><category term="italia.it" /><category term="draft 76" /><category term="transform" /><category term="quit" /><category term="loader" /><category term="ExtJS" /><category term="trimRight" /><category term="LiveMonitor" /><category term="font-face" /><category term="bridge" /><category term="example" /><category term="UX" /><category term="DELAYED" /><category term="setAttribute" /><category term="Subclass" /><category term="memory" /><category term="lambda" /><category term="NWMatcher" /><category term="native" /><category term="record" /><category term="server side" /><category term="polyfill" /><category term="beta" /><category term="shim" /><category term="JavaScript Hijacking" /><category term="read" /><category term="execution" /><category term="dojo" /><category term="iPhone" /><category term="text" /><category term="build" /><category term="280" /><category term="holidays" /><category term="practices" /><category term="optimization" /><category term="OOP" /><category term="responsive" /><category term="circle" /><category term="NHS" /><category term="Widget" /><category term="navigator" /><category term="VS" /><category term="IndexedDB" /><category term="grab" /><category term="epic" /><category term="binary safe" /><category term="project" /><category term="love" /><category term="content" /><category term="Event" /><category term="Python" /><category term="es4" /><category term="operator" /><category term="slice" /><category term="challenge" /><category term="no flash" /><category term="support" /><category term="JS1K" /><category term="client" /><category term="bin" /><category term="magic" /><category term="ISO" /><category term="folder" /><category term="XMLHttpRequest" /><category term="JSConf" /><category term="ActionScript" /><category term="eval" /><category term="input" /><category term="typeof" /><category term="tag" /><category term="Portable" /><category term="mixins" /><category term="London" /><category term="PyramiDOM" /><category term="Pure DOM" /><category term="instanceof" /><category term="png" /><category term="Libraries" /><category term="Object.createStatic" /><category term="inherit" /><category term="PAMPA" /><category term="Scala" /><category term="Spectrum" /><category term="Tokens" /><category term="Composite" /><category term="overloading" /><category term="no swf" /><category term="AMD" /><category term="access" /><category term="canvas" /><category term="textarea" /><category term="statement" /><category term="configurable" /><category term="classical" /><category term="Storage" /><category term="blocked" /><category term="Components" /><category term="Comet" /><category term="JSON" /><category term="comments" /><category term="Ad 2.0" /><category term="Factory" /><category term="URLs" /><category term="promotion" /><category term="Satay" /><category term="recovery" /><category term="embedded" /><category term="Konami" /><category term="speed" /><category term="sourceIndex" /><category term="MyMin" /><category term="$super" /><category term="homogeneous" /><category term="recruiters" /><category term="hpack" /><category term="tweetcode" /><category term="deployment" /><category term="5.3.5" /><category term="ellipse" /><category term="migration" /><category term="steal" /><category term="Stack" /><category term="post" /><category term="packed" /><category term="Google" /><category term="ie" /><category term="Set" /><category term="replace" /><category term="coercion" /><category term="Internet Explorer 8" /><category term="setInterval" /><category term="JavaScript.document" /><category term="host objects" /><category term="smoking" /><category term="JsonReader" /><category term="closure" /><category term="WebGL" /><category term="extras" /><category term="server" /><category term="asyncStorage" /><category term="If" /><category term="questions" /><category term="AMF" /><category term="Serializable" /><category term="haxe" /><category term="problem" /><category term="Rebecca Murphey" /><category term="Adapter" /><category term="JS.next" /><category term="IE9" /><category term="fireEvent" /><category term="Strict" /><category term="3site.it" /><category term="INSERT" /><category term="parent" /><category term="getter" /><category term="isNative" /><category term="packed.it" /><category term="syntax" /><category term="sub" /><category term="JavaScript.PHP" /><category term="Web" /><category term="firefox" /><category term="test" /><category term="values" /><category term="KISS" /><category term="DOM" /><category term="window" /><category term="tips" /><category term="link" /><category term="advertisement" /><category term="JScript" /><category term="freeze" /><category term="bind" /><category term="multiple" /><category term="future" /><category term="stringify" /><category term="buttons" /><category term="Lion" /><category term="XSLT" /><category term="MySQL" /><category term="WebSocket" /><category term="Nokia" /><category term="security" /><category term="mistakes" /><category term="look" /><category term="Douglas Crockford" /><category term="extend" /><category term="__noSuchMethod__" /><category term="Xpath" /><category term="fuckn.es" /><category term="Collection" /><category term="Worker" /><category term="nested" /><category term="editor" /><category term="YUICompressor" /><category term="protected" /><category term="Symbol" /><category term="custom" /><category term="View" /><category term="JSONP" /><category term="CoffeeScript" /><category term="bar" /><category term="Mouse" /><category term="escape" /><category term="Regular" /><category term="Tree" /><category term="base" /><category term="IE8" /><category term="Jaxer" /><category term="html" /><category term="EU" /><category term="scroll" /><category term="let" /><category term="quality" /><category term="selector" /><category term="fun" /><category term="trimLeft" /><category term="methods" /><category term="Phico" /><category term="encode" /><category term="JavaScript" /><category term="serialize" /><category term="request" /><category term="zlib" /><category term="uri" /><category term="ft2010" /><category term="out of order" /><category term="myth" /><category term="GeoLocation" /><category term="transpiler" /><category term="Template" /><category term="proxy" /><category term="asynchronous" /><category term="getPropertyDescriptor" /><category term="Sniff" /><category term="mock" /><category term="ECMAScript" /><category term="mjst" /><category term="load" /><category term="environment" /><category term="all" /><category term="unshared" /><category term="hart" /><category term="export" /><category term="Front" /><category term="cheat" /><category term="easy" /><category term="Ajax" /><category term="form" /><category term="compression" /><category term="LLVM" /><category term="bing" /><category term="toy" /><category term="is_a" /><category term="setter" /><category term="__sleep" /><category term="cross-browser" /><category term="domain" /><category term="impression" /><category term="spell" /><category term="Android" /><category term="Caja" /><category term="const" /><category term="subclassed" /><category term="setTimeout" /><category term="wrong" /><category term="minification" /><category term="element" /><category term="guide" /><category term="Cookie" /><category term="override" /><category term="convert" /><category term="RC4" /><category term="static" /><category term="programming" /><category term="document" /><category term="usable" /><category term="objects" /><category term="safe" /><category term="name" /><category term="single" /><category term="__wakeup" /><category term="WeakMap" /><category term="expression" /><category term="JsonML" /><category term="first" /><category term="__proto__" /><category term="book" /><category term="blog" /><category term="Web 2.0" /><category term="Phomet" /><category term="Liquid" /><category term="position" /><category term="cross-platform" /><category term="ECMAScript 5" /><category term="isPrototypeOf" /><category term="Callback" /><category term="mode" /><category term="Number" /><category term="implicit" /><category term="NekoVM" /><category term="handshake" /><category term="JHP" /><category term="languages" /><category term="RitaliaCamp1" /><category term="exit" /><category term="Netbook" /><category term="Rant" /><category term="fail" /><category term="snow" /><category term="data" /><category term="progress" /><category term="reader" /><title type="text">Web Reflection</title><subtitle type="html">behind the design</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://webreflection.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default?start-index=26&amp;max-results=25" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>527</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/WebReflection" /><feedburner:info uri="webreflection" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry><id>tag:blogger.com,1999:blog-34454975.post-2346263200788268260</id><published>2013-05-16T06:29:00.000+02:00</published><updated>2013-05-18T00:58:20.809+02:00</updated><title type="text">Object.setPrototypeOf(O, proto) IS in ES6</title><content type="html">This one is a short one, just to confirm that finally &lt;code&gt;Object.setPrototypeOf(obj, proto)&lt;/code&gt; &lt;a href="http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#current_working_draft"&gt;made it into ES6&lt;/a&gt;.&lt;br/&gt;The section &lt;strong&gt;15.2.3.2&lt;/strong&gt; speaks clearly: &lt;blockquote&gt;&lt;strong&gt;15.2.3.2 Object.setPrototypeOf ( O, proto )&lt;/strong&gt;&lt;br/&gt;When the &lt;code&gt;setPrototypeOf&lt;/code&gt; function is called with arguments O and proto, the following steps are taken: &lt;ol&gt;&lt;li&gt;If Type(O) is not Object, then throw a &lt;strong&gt;TypeError&lt;/strong&gt; exception.&lt;/li&gt;&lt;li&gt;If Type(proto) is neither Object or Null, then throw a &lt;strong&gt;TypeError&lt;/strong&gt; exception.&lt;/li&gt;&lt;li&gt;Let status be the result of calling the [[SetInheritance]] internal method of O with argument proto.&lt;/li&gt;&lt;li&gt;ReturnIfAbrupt(status).&lt;/li&gt;&lt;li&gt;If status is false, then throw a &lt;strong&gt;TypeError&lt;/strong&gt; exception.&lt;/li&gt;&lt;li&gt;Return O.&lt;/li&gt;&lt;/ol&gt;&lt;/blockquote&gt;Without going into details, the most basic polyfill woud be like this: &lt;pre class="code"&gt;&lt;br /&gt;(function(O,s){&lt;br /&gt;O[s]||(O[s]=function(o,p){o.__proto__=p;return o})&lt;br /&gt;}(Object,'setPrototypeOf'));&lt;br /&gt;&lt;/pre&gt;If you want to go into details, the full reliable polyfill is hard to write down due all inconsistencies across JS engines out there where the __proto__ setter cannot be reused which means it's not possible to trust this magic over objects created from null.&lt;br/&gt;All you need to do is forget __proto__ and use the suggested polyfill until the day __proto__ can simply disappear from those specs pages.&lt;br/&gt;Enjoy! &lt;hr/&gt;This is a full polyfill with some extra info you might want to analyze, whenever ployfill is strictly true or false.&lt;br/&gt;&lt;script src="https://gist.github.com/WebReflection/5593554.js"&gt;&lt;/script&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/2346263200788268260/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=2346263200788268260" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/2346263200788268260" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/2346263200788268260" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/x1SntOIIwio/objectsetprototypeofo-proto-is-in-es6.html" title="Object.setPrototypeOf(O, proto) IS in ES6" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>3</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/05/objectsetprototypeofo-proto-is-in-es6.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-5220325424155488363</id><published>2013-04-27T10:56:00.000+02:00</published><updated>2013-04-29T20:55:00.158+02:00</updated><title type="text">Few Modern JavaScript Inconsistencies</title><content type="html">&lt;p&gt;While the JavaScript weekly mailing list still &lt;a href="https://twitter.com/WebReflection/status/327833810580434944"&gt;points to 90s style articles about the old JavaScript Internet Explorer 5 was supporting too&lt;/a&gt;, the current world has different real problems to consider.&lt;br/&gt; Here a quick list of things you might not know about the current status of JavaScript possibilities. &lt;/p&gt; &lt;h3&gt;Reserved Words As Properties&lt;/h3&gt;&lt;p&gt;Number one of the list is the myth that reserved words cannot be used as properties. Here platforms that cannot: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;iOS 4&lt;/li&gt;&lt;li&gt;IE less than 9&lt;/li&gt;&lt;li&gt;Android less than 2.1&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;So, basically, 99% of mobile browsers support properties such &lt;code&gt;obj.delete()&lt;/code&gt;, used in most recent JavaScript specifications, while those jurassic browsers need the &lt;code&gt;obj['delete']()&lt;/code&gt; convention. &lt;/p&gt; &lt;pre class="code"&gt;&lt;br /&gt;// exactly same good old ES3 behavior&lt;br /&gt;// using ES5 capabilities&lt;br /&gt;Function.prototype.new = function () {&lt;br /&gt;  var&lt;br /&gt;    // grab the prototype&lt;br /&gt;    p = this.prototype,&lt;br /&gt;    // create from it&lt;br /&gt;    o = Object.create(p),&lt;br /&gt;    // invoke the real constructor&lt;br /&gt;    r = this.apply(o, arguments);&lt;br /&gt;  // if the result is not undefined or null&lt;br /&gt;  // and the returned value is an object/function&lt;br /&gt;  // overwrite the result&lt;br /&gt;  return r != null &amp;&amp; (&lt;br /&gt;    typeof r === 'object' ||&lt;br /&gt;    typeof r === 'function'&lt;br /&gt;  ) ? r : o;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// you can be Rubyish now ^_^&lt;br /&gt;var instance = MyClass.new(1, 2, 3);&lt;br /&gt;&lt;br /&gt;// P.S. if you have problems with JSLint&lt;br /&gt;// and the r != null part in above snippet&lt;br /&gt;// it's just time for you to upgrade to JSHint&lt;br /&gt;&lt;/pre&gt; &lt;h4&gt;Please Do Not Support Too Old Browsers&lt;/h4&gt;&lt;p&gt;As easy as that. As a developer, company, software provider, whatever, you are trapping yourself behind problems that will never be fixed in those browsers and you are limiting your customer too, embracing development for such old environment, instead of promoting an update that will benefit them in terms of both potentials, expenses, and security.&lt;br/&gt;Any company that will say no to that should be kindly be abandoned, IMHO, they're already out of web/JS business and they don't realize yet.&lt;br/&gt;I understand some graceful measurement should be taken in order to migrate old users, but as long as they feel confortable, they won't migrate sooner for sure.&lt;br/&gt;Customers or people we'd like to let them access our service, should be informed somehow of new possibilities too. &lt;/p&gt; &lt;h4&gt;Apple Drops 3 Years Old Software Too&lt;/h4&gt;&lt;p&gt;If &lt;a href="https://developer.apple.com/news/index.php?id=3212013b"&gt;Apple not accepting non retina software anymore&lt;/a&gt; is not enough as an argument, think how many possibilities you are dropping to your software in order to work the same in those old browsers.&lt;br/&gt;You chose Web technologies, you should catch up with these, end of the story. &lt;/p&gt; &lt;h3&gt;Object.defineProperty() *Is* Available&lt;/h3&gt;&lt;p&gt;Even my Palm Pre 2 webOS supports &lt;code&gt;Object.defineProperty()&lt;/code&gt;, together with &lt;code&gt;Object.defineProperties()&lt;/code&gt;, &lt;code&gt;Object.getPrototypeOf()&lt;/code&gt; and &lt;code&gt;Object.getOwnPropertyDescriptor()&lt;/code&gt;!&lt;br/&gt;If you don't want to deal with all this verbosity but you like the power behind, &lt;a href="https://github.com/WebReflection/redefine#redefinejs"&gt;redefine&lt;/a&gt; is really your best friend then! &lt;/p&gt;&lt;p&gt;The most widely adopted list of ES5 features down to Android 2.1 phones and webOS are: &lt;/p&gt;&lt;ol&gt;  &lt;li&gt;&lt;code&gt;Object.create()&lt;/code&gt;&lt;/li&gt;  &lt;li&gt;&lt;code&gt;Object.defineProperty()&lt;/code&gt;&lt;/li&gt;  &lt;li&gt;&lt;code&gt;Object.defineProperties()&lt;/code&gt;&lt;/li&gt;  &lt;li&gt;&lt;code&gt;Object.getOwnPropertyNames()&lt;/code&gt;&lt;/li&gt;  &lt;li&gt;&lt;code&gt;Object.getOwnPropertyDescriptor()&lt;/code&gt;&lt;/li&gt;  &lt;li&gt;&lt;code&gt;Object.getPrototypeOf()&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Things like &lt;code&gt;Object.freeze()&lt;/code&gt; might have been introduced later on so don't trust them ... but, whenever you wanna try that: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;var freeze = Object.freeze || Object;&lt;br /&gt;freeze({}); // frozen where possible&lt;br /&gt;&lt;br /&gt;function returnFrozen(object) {&lt;br /&gt;  return (Object.freeze || Object)(object);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;As it is for &lt;code&gt;"use strict";&lt;/code&gt; and all other things that works best natively, above technique will work with &lt;code&gt;Object.seal()&lt;/code&gt;, &lt;code&gt;Object.preventExtensions()&lt;/code&gt;, and why not, a shimmable &lt;code&gt;Object.isExtensible()&lt;/code&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;'isExtensible' in Object || (function(){&lt;br /&gt;  // no way ES3 can prevent extension so ...&lt;br /&gt;  Object.isExtensible = function (object) {&lt;br /&gt;    // ... if an object, it's extensible&lt;br /&gt;    return object != null &amp;&amp; (&lt;br /&gt;      typeof object === 'object' ||&lt;br /&gt;      typeof object === 'function'&lt;br /&gt;    )&lt;br /&gt;  };&lt;br /&gt;}());&lt;br /&gt;&lt;/pre&gt; &lt;h3&gt;Function.prototype get caller() {return WTF}&lt;/h3&gt;&lt;p&gt;Generally speaking the &lt;code&gt;caller&lt;/code&gt; property works since ever but there are cases where it does not and this is &lt;strong&gt;iOS5&lt;/strong&gt; and lower fault.&lt;br/&gt;What am I talking about? About &lt;a href="https://bugs.webkit.org/show_bug.cgi?id=45480"&gt;caller over getters&lt;/a&gt;, with or without &lt;code&gt;__defineGetter__&lt;/code&gt; old style approach, the new one fails too ^_^&lt;br/&gt;Bear in mind iOS 5.1 and 6.0+ are just fine so you can still use that magic, if needed.&lt;br/&gt;Note a part, &lt;a href="http://www.mail-archive.com/es-discuss@mozilla.org/msg19359.html"&gt;that magic ain't disappearing any time soon&lt;/a&gt; so ... go on, use &lt;code&gt;caller&lt;/code&gt; until there is an alternative: so far, not a single one ^_^ &lt;/p&gt; &lt;h3&gt;Function.prototype.bind()&lt;/h3&gt;&lt;p&gt;It took literarily ages for WebKit to adopt this method so this is something available in all modern browsers but most likely not available with not so old mobile one: easy shim from &lt;a href="https://github.com/WebReflection/caller-of"&gt;callerOf&lt;/a&gt;! &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;(function (P, l) {&lt;br /&gt;  'use strict';&lt;br /&gt;  if (!P.bind) {&lt;br /&gt;    P.bind = function (s) {&lt;br /&gt;      var&lt;br /&gt;        c = this,&lt;br /&gt;        a = l.call(arguments, 1);&lt;br /&gt;      return function bind() {&lt;br /&gt;        return c.apply(s, a.concat(l.call(arguments)));&lt;br /&gt;      };&lt;br /&gt;    };&lt;br /&gt;  }&lt;br /&gt;}(Function.prototype, [].slice));&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;This is the kind of code that I would like to see in CDN, not just 50K libraries for client sake! &lt;/p&gt; &lt;h3&gt;Avoid __proto__&lt;/h3&gt;&lt;p&gt;Not only conceptually an error and used only to gain some arguable performance boost, &lt;code&gt;__proto__&lt;/code&gt; is absolutely something that IE 10 and 9 will never have in a consistent way. &lt;/p&gt;&lt;p&gt;If you want to transform a list into an array, just &lt;code&gt;var slice = Function.call.bind([].slice);&lt;/code&gt; so that you can &lt;code&gt;slice(whatever, optionalIndex)&lt;/code&gt; ALL the things, right? The &lt;code&gt;bind()&lt;/code&gt; is there and costs nothing ... just use it! &lt;/p&gt;  &lt;h3&gt;Better Than Zepto&lt;/h3&gt;&lt;p&gt;What &lt;a href="https://github.com/madrobby/zepto/commit/66d84a05f8460f00dcf62cb610c0f12f606eff03#L0R138"&gt;this library is doing&lt;/a&gt;, except from &lt;a href="http://ie.microsoft.com/testdrive/mobile/"&gt;ignoring IE as a Mobile browser&lt;/a&gt;, is a poor/quick&amp;dirty design/convention to obtain a prototype swap instead of initializing things in the right way.&lt;br/&gt;The previously linked code could be represented by exactly the same syntax: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;// an IE9 and 10 compatible zero bullshit Zepto core&lt;br /&gt;var emptyArray = [];&lt;br /&gt;zepto.Z = function(dom, selector) {&lt;br /&gt;  var result = Object.create($.fn);&lt;br /&gt;  emptyArray.push.apply(&lt;br /&gt;    result, dom || emptyArray&lt;br /&gt;  );&lt;br /&gt;  result.selector = selector || '';&lt;br /&gt;  return result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;While &lt;a href="http://jsperf.com/proto-vs-noproto"&gt;performance might not be that good in some engine&lt;/a&gt;, and everybody knows that you should never &lt;code&gt;$('select')&lt;/code&gt; twice per collection so actually, considering above snippet goes 400.000 objects per seconds, that's not a big/real deal at all!&lt;br/&gt;If that is, I tell you something else is wrong in the app logic!&lt;br/&gt;In any case, &lt;strong&gt;actually&lt;/strong&gt;, there's some mobile platform there, those Zepto thinks is supporting, that scores more with lower results than with a prototype swap, which is the most common selector case, BlackBerry 10 is 8 thousands operations per seconds there compared with &lt;code&gt;__proto__&lt;/code&gt;&lt;br/&gt;Thomas Fuchs has been so nice in his repository I cannot even push/contributes these improvements ... surely &lt;a href="https://github.com/madrobby/zepto/pull/736#issuecomment-16857282"&gt;he would get this one as an insult too&lt;/a&gt;, isn't it? &lt;/p&gt; &lt;h3&gt;A Swap Oriented __proto__ Attempt&lt;/h3&gt;&lt;p&gt;Assuming you still want to swap runtime classes because you cannot define a proper inheritance upfront, here a broken attempt to do that in IE8 and lower: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;object = dunder(object, proto);&lt;br /&gt;&lt;/pre&gt; &lt;h4&gt;what's dunder()&lt;/h4&gt;&lt;p&gt;&lt;a href="https://github.com/WebReflection/dunder"&gt;dunder()&lt;/a&gt; is my attempt to bring a friendly cross platform way, included older IE, to swap proto at runtime.&lt;br/&gt;It requires an assignment so, back to Zepto example, &lt;code&gt;return dunder(dom || [], $.fn)&lt;/code&gt; would be all you need to make it work everywhere. &lt;/p&gt; &lt;h3&gt;JSON.stringify(object, *replacer*)&lt;/h3&gt;&lt;p&gt;This is Safari specific gotcha, and it's about the replacer.&lt;br/&gt;While &lt;a href="http://es5.github.io/#Walk"&gt;specs say&lt;/a&gt; that &lt;code&gt;Let newElement be the result of calling the abstract operation Walk, passing val and **ToString**(I)&lt;/code&gt;, Safari will send to the receiver the number &lt;code&gt;0&lt;/code&gt; instead of the string &lt;code&gt;'0'&lt;/code&gt;.&lt;br/&gt;What's the big deal here? That in JavaScript, &lt;code&gt;0 == false&lt;/code&gt; while &lt;code&gt;'0' == true&lt;/code&gt; so ... if you have this kind of check in your receiver thinking that if empty, nothing should be done: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;if (key) {&lt;br /&gt;  // parse your value&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Improve that check with &lt;code&gt;if (key === '')&lt;/code&gt;, probably the only place on earth where JSLint would have helped you for real instead of messing up your own code. &lt;/p&gt;&lt;p&gt;And for today, that's all folks! &lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/5220325424155488363/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=5220325424155488363" title="7 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5220325424155488363" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5220325424155488363" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/yMf83ckImLU/few-modern-javascript-inconsistencies.html" title="Few Modern JavaScript Inconsistencies" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>7</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/few-modern-javascript-inconsistencies.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-9044586168337570393</id><published>2013-04-24T10:07:00.000+02:00</published><updated>2013-04-24T10:07:22.093+02:00</updated><title type="text">Boot To Node.js In 7 Seconds On Arch Linux</title><content type="html">&lt;p&gt;This is a long story that started with me buying a &lt;a href="http://www.raspberrypi.org/"&gt;Raspberry Pi&lt;/a&gt; with the goal of discovering how good performance could have been in such device used as dedicated server.&lt;br/&gt;The story goes on with pcDuino too, and tricks you might want to know about booting up and building node on them. &lt;/p&gt; &lt;h3&gt;Why A Pi As A Server&lt;/h3&gt;&lt;p&gt;The story of computers is not actually that fair for same computers, as not fair is the &lt;a href="http://en.wikipedia.org/wiki/Moore's_law"&gt;Moore's law&lt;/a&gt; itself.&lt;br/&gt;Bear in mind, I am not saying that's not working, all I am saying is that if in 6 months we've got double amount of transistors in some CPU, this does not mean we've been used the previous CPU at its best for last 6 months! &lt;/p&gt;&lt;p&gt;Gaming, immortal, consoles such &lt;a href="http://us.playstation.com/ps2/"&gt;PS2&lt;/a&gt; can describe better than my words what I am talking about: hardware is good until what you need does not fit under that 100% of potentials! &lt;/p&gt; &lt;h3&gt;ARM Is Powerful&lt;/h3&gt;&lt;p&gt;Not only is becoming one of the most ambitious target for any Operating System, probably including Microsoft, ARM is also both powerful and power consumption aware, something we've never rarely thought about before .. I mean, a server that does not need much electricity so that if some blackout happens it does not dry whatever counter blackout part is playing in the building? And what about a web farm? &lt;/p&gt; &lt;h3&gt;A Raspberry Pi Web Hosting Colocation&lt;/h3&gt;&lt;p&gt;Yes, it's not just me, and actually ... WTF!&lt;br/&gt;When I've invested a bit of extra time trying to have up and running my own idea of a co-location, &lt;a href="http://raspberrycolocation.com/"&gt;raspberrycolocation.com&lt;/a&gt; was born instead and sold out ... gosh I'm always late at the party!&lt;br/&gt;What this smart guys did, is to offer a full server for about $50, being absolutely the most competitive dedicated server company in the world right now ... that's as easy as that .... &lt;strong&gt;but&lt;/strong&gt; ... &lt;/p&gt; &lt;h3&gt;Arch linux&lt;/h3&gt;&lt;p&gt;What those guys offer is a colocation for your own Pi, a device I honestly would never put into anybody else hands (and that's the feeling you have when that little thing works as hell with awesome performance under your own software) over the Raspbian distro, surely a stable, well tested, etc, etc linux based OS, unfortunately kinda/"slightlier" heavy :(&lt;br/&gt;R-Pi aim is to be a cheap replacement for a PC and in this case Raspbian is the most suitable distro you have there.&lt;br/&gt;However, if you are planning to do something different that does not requires a GUI, and RAM is only 512 there, or any other extra thing on top, Arch Linux becomes the best alternative for this device. &lt;/p&gt;&lt;p&gt;The part I love the most about &lt;a href="https://www.archlinux.org/"&gt;Arch Linux&lt;/a&gt;, is that it basically embraces my same philosophy when it comes to JavaScript or, generally speaking, programming with dependencies .... the less I have and the more I know about the app, the faster I move when it comes to add something, fix something, or experiment! (you should try this approach instead of putting, as example, jQuery or Zepto by default in your web page, it works, trust me!) &lt;/p&gt; &lt;h4&gt;Living On The Edge&lt;/h4&gt;&lt;p&gt;This Aerosmith song is probably looping inside any Arch Linux contributor, as this distribution is nothing about having frozen modules that pass some test and until tested everywhere else will never work, this distro is about having always the latest available software in your system, which will result in a freaking cool, always updated one, as ready for production as much as your node.js project or website is ... I mean, isn't modern JavaScript culture about serving what's the best thing available today? I love that too! &lt;/p&gt; &lt;h4&gt;410+ MB of RAM&lt;/h4&gt;&lt;p&gt;You don't need me to try the Raspbian distro and check how much &lt;code&gt;require('os').freemem();&lt;/code&gt; command will return in node pre 0.11.2, you can install the package instead of compiling it on the hardware as I am doing, and do the math.&lt;br/&gt;If the device has 512MB of RAM, 410+ after OS booted in about 8 seconds ain't that bad, right? And I am sure the distro coul dbe even more minimalistic ... as it is, as example in the following platform: &lt;/p&gt;  &lt;h3&gt;The Allwinner 10&lt;/h3&gt;&lt;p&gt;If I have to be honest with you, &lt;a href="http://www.allwinner.com/product/A10.php"&gt;I would rather consider this platform&lt;/a&gt;, or any of its new derived, more than a Pi.&lt;br/&gt;I know, kids price not so friendly, but here you have an ARMv7 with most likely at least 1Ghz of clock speed and 1GB of RAM over some NAND which is alwas faster than inboard SD controller (I'll come back on this part too) &lt;/p&gt; &lt;h4&gt;The &lt;a href="http://www.pcduino.com/"&gt;pcDuino&lt;/a&gt; Case&lt;/h4&gt;&lt;p&gt;As example, you can have an Arch Linux distro able to boot up in 6 seconds into node.js, with an average of &lt;code&gt;0.3%&lt;/code&gt; of &lt;strong&gt;CPU&lt;/strong&gt; usage via &lt;em&gt;SSH&lt;/em&gt; to monitor what's going on behind the &lt;code&gt;top&lt;/code&gt; scene! &lt;/p&gt;&lt;p&gt;If you try to do the same with the minimalistic full Desktop version of Ubuntu for this device, you'll notice at least &lt;em&gt;6 to 9% of default CPU usage&lt;/em&gt; because of the graphic OS, plus &lt;em&gt;691511296&lt;/em&gt; of available RAM after boot against a &lt;code&gt;require('os').freemem()&lt;/code&gt; resut of &lt;em&gt;797020160&lt;/em&gt; for the Arch Linux headless distro .. yeah, you heard that right! &lt;/p&gt; &lt;h4&gt;Slow Down, You Punk!&lt;/h4&gt;&lt;p&gt;While Raspberry Pi has a pretty decent and complete image of Arch Linux that includes all hardware activation at boot time, no led excluded, pcDuino is kinda "problematic" as any Allwinner platform is because of the not so stable graphic videos ... who cares indeed! &lt;/p&gt;&lt;p&gt;If your goal is to have a dedicated server on the palm of your hand, the graphic whatever is something you won't care at all. I agree this might sound confusing at the beginning, if you are not familiar with linux bootable distros, but hey ... the video is such a pain in your spine I am not sure you really want to know how to fix that, do you? &lt;/p&gt; &lt;h3&gt;Install Arch Linux In Allwinner A10 ARM Devices&lt;/h3&gt;&lt;p&gt;&lt;a href="http://archlinuxarm.org/forum/viewtopic.php?f=9&amp;t=5334&amp;start=10"&gt;This post&lt;/a&gt; and its &lt;i&gt;welcomeness&lt;/i&gt; are kinda the beginning of the story about Arch Linux.&lt;br/&gt;What you think makes sense for an OS ... well, you are already out of sync: Arch is kinda the skeleton of that OS, anything else is your choice/matter/problem/duty, if you want to support that platform. &lt;/p&gt; &lt;h4&gt;Even More Annoying&lt;/h4&gt;&lt;p&gt;Is not just the fact if you are noob in *nix world you should drop this distro by default since nobody wants to deal with you, &lt;a href="http://archlinuxarm.org/platforms/armv7/pcduino"&gt;the instructions&lt;/a&gt;, even if you are part of that world, are kinda crap too. &lt;/p&gt; &lt;h4&gt;Thank You &lt;a href="http://andre.blaatschaap.be/"&gt;André&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;Despite André post talks about a different A10 board, the used code is clearly something you might find handy, once re-elaborated as such: &lt;/p&gt;&lt;script src="https://gist.github.com/WebReflection/5450375.js"&gt;&lt;/script&gt;&lt;p&gt;In my case I had to: &lt;/p&gt;&lt;pre&gt;&lt;br /&gt;sh a10.sh /dev/sdb pcduino-bootloader.tar.gz pcduino&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;after changing things might be different for other A10 boards. &lt;/p&gt; &lt;h3&gt;As Result&lt;/h3&gt;&lt;p&gt;I've been impressed by &lt;a href="https://github.com/WebReflection/polpetta#-polpetta"&gt;polpetta&lt;/a&gt; performance, as generic hard drive surfer/common intra-cloud, on a network of 15+ devices: not a glitch over these platforms under hand compiled node.js 11.2 versions.&lt;br/&gt;The average ping for this device in the network is 1.3 milli seconds, which is nothing!&lt;br/&gt;Are you sure your initial web business demands much more as dedicated server?&lt;br/&gt;What if a $40 dollars board plus SD card is all you need, to measure your startup success? &lt;/p&gt; &lt;h3&gt;What's With SD Cards&lt;/h3&gt;&lt;p&gt;The situation around SD Cards is awkward at least. So here the thing, I haven't spot any difference between an &lt;a href="http://www.sandisk.com/products/memory-cards/microsd/extremepro-uhs-i/?capacity=8GB"&gt;8GB Extreme Pro&lt;/a&gt; SanDisk micro SD Card, and an &lt;a href="http://www.sandisk.com/products/memory-cards/microsd/ultra-class10-for-android/?capacity=32GB"&gt;Ultra 32GB&lt;/a&gt; version of the micro usb card ... but more over, I don't think you need such amount of space for any of these devices since even looping through FileSystem tables has a cost I believe your cheap ARM dedicated web server should not take into consideration ;) &lt;/p&gt;&lt;p&gt;Have fun with hints on the web about how to build your first dedicated web host in no more than $100 for years, network a part! &lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/9044586168337570393/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=9044586168337570393" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/9044586168337570393" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/9044586168337570393" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/ZiSH-6tKw_0/boot-to-nodejs-in-7-seconds-on-arch.html" title="Boot To Node.js In 7 Seconds On Arch Linux" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/boot-to-nodejs-in-7-seconds-on-arch.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-138919135615567944</id><published>2013-04-21T07:34:00.001+02:00</published><updated>2013-04-21T08:53:54.711+02:00</updated><title type="text">The __proto__ Comic</title><content type="html">&lt;p&gt;&amp;copy; all images from &lt;a href="http://ragefac.es/"&gt;ragefac.es&lt;/a&gt; and some from &lt;a href="http://knowyourmeme.com/"&gt;knowyourmeme&lt;/a&gt;&lt;br/&gt;Being a comic, sentences are not all real, mostly made up for this post. &lt;/p&gt; &lt;h4&gt;TC39&lt;/h4&gt;&lt;p&gt;WTF is this shit?! &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/503cff15ae7c707d56000007/966412cc1838c13ee0349b4a05a17802.png"/&gt; &lt;h4&gt;es-discuss&lt;/h4&gt;&lt;p&gt;The community needs it and the de-facto library with stars on github uses that instead of &lt;code&gt;[].push.call(new SimplifiedDOMShit, NodeListResult)&lt;/code&gt;&lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/504083e1ae7c70058a000007/1f599c7cc95c3e4ff801a024cba54af4.png"/&gt; &lt;h4&gt;TC39&lt;/h4&gt;&lt;p&gt;OK, here what we can spec ... making it configurable, so that shit can be dropped at any time in any module &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/50420161ae7c705103000001/facepalm-startrek.png"/&gt; &lt;h4&gt;es-discuss&lt;/h4&gt;&lt;p&gt;Community, we are going to spec &lt;codo&gt;__proto__&lt;/code&gt; shenanigans all over so that any environment will have a special property able to cause more disasters than what &lt;code&gt;eval&lt;/code&gt; did before: you should appreciate! &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/504083e1ae7c70058a000007/1f599c7cc95c3e4ff801a024cba54af4.png"/&gt; &lt;h4&gt;community&lt;/h4&gt;&lt;p&gt;so, proto gonna be standard we don't have to change those 2 lines of code?! &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/503e51d3ae7c700dcb0000c3/418640e644cacf9b47a464cc758f2019.png"/&gt; &lt;h4&gt;me plus some other&lt;/h4&gt;&lt;p&gt;what kind of horrible decision is this? &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/5041e193ae7c704e28000009/terrified.png"/&gt; &lt;h4&gt;es-discuss&lt;/h4&gt;&lt;p&gt;&lt;cite&gt;de-facto is de-facto&lt;/cite&gt;, people use this, people want this! IE ... who cares ! &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/504083e1ae7c70058a000007/1f599c7cc95c3e4ff801a024cba54af4.png"/&gt; &lt;h4&gt;just me&lt;/h4&gt;&lt;p&gt;OK, probably this is just a massive misunderstanding between what's truly needed, and what should be proposed ... let's try to fight back in es-discuss ... &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/503e40b2ae7c700dcb00009e/65d8b4ec625b745f30bd222de938f6e1.png"/&gt; &lt;h4&gt;es-discuss&lt;/h4&gt;&lt;p&gt;You don't understand, you are late, even if not spec'd yet, you are really late &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/504083e1ae7c70058a000007/1f599c7cc95c3e4ff801a024cba54af4.png"/&gt;  &lt;h4&gt;just me&lt;/h4&gt;&lt;p&gt;I gonna show you that JavaScript developers understand this is a no-go and it's bad for the language they use on daily basis as bad, and even worse than boring &lt;code&gt;hasOwnProperty&lt;/code&gt; check has been for all these years! &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/503e3c0dae7c700dcb000059/8258ec1e8eb8e366c4ce496df611bf80.png"/&gt;  &lt;h4&gt;still me&lt;/h4&gt;&lt;p&gt;Hello Zepto, somebody thinks we are all bigots unable to make simple changes ... here the patch for you repo, it's green, it works, it has no side effect, it demonstrates we are not bigots, what do you say? &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/50410019ae7c70217a000012/b8189952eafb6c21a94e7961bc1a4a14.png"/&gt;  &lt;h4&gt;Zepto.js&lt;/h4&gt;&lt;p&gt;You &lt;cite&gt;White Knight&lt;/cite&gt; bla, bla, bla ... horse shit bla ... &lt;/p&gt;&lt;img width="200" src="http://www.3site.eu/images/zepto.png"/&gt;  &lt;h4&gt;just me&lt;/h4&gt;&lt;p&gt;WTF? I can't even explain myself there, they blocked me ... what should I do? &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/503e3b03ae7c700dcb000057/1e6b90eb5b4fd404356004c534bfa613.png"/&gt;  &lt;h4&gt;still just me&lt;/h4&gt;&lt;p&gt;... well, I gonna see if at least node.js community, with much more unified environment, &lt;a href="https://github.com/joyent/node/pull/5341#issuecomment-16698948"&gt;would accept a proposal&lt;/a&gt;... &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/503e3c6eae7c700dcb000061/fbce935cecab355b9d5e8f300f1cb18b.png"/&gt;  &lt;h4&gt;still me&lt;/h4&gt;&lt;p&gt;Hello node, here a patch that is waiting for a patch in V8 so the patch gonna patch the patch, what do you say? &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/50410019ae7c70217a000012/b8189952eafb6c21a94e7961bc1a4a14.png"/&gt; &lt;h4&gt;node.js&lt;/h4&gt;&lt;p&gt;&lt;cite&gt;We don't extend the language and we don't impose coding standards on our users.&lt;/cite&gt;&lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/50408475ae7c70058a00000d/b4a228d250fe2d155e6e9ff2fae3957a.png"/&gt;  &lt;h4&gt;again me&lt;/h4&gt;&lt;p&gt;Will you consider at least this .. or that ... ? &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/503e3715ae7c700dcb000032/8369578306dbfa070fc8c051311108bf.png"/&gt;  &lt;h4&gt;again node.js&lt;/h4&gt;&lt;p&gt;&lt;cite&gt;But we're not going to float a patch that adds this feature to V8&lt;/cite&gt;&lt;/p&gt;&lt;img width="200" src="http://i3.kym-cdn.com/photos/images/newsfeed/000/232/114/e39.png"/&gt; &lt;h4&gt;still just me&lt;/h4&gt;&lt;p&gt;... well, I gonna see if at least V8 will accept my flag that gonna affect node at startup ... &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/506dfa12ae7c7001e4000002/okay.png"/&gt; &lt;h4&gt;V8&lt;/h4&gt;&lt;p&gt;Well, I don't know if &lt;a href="https://code.google.com/p/v8/issues/detail?id=2645"&gt;V8 will ever accept my patch&lt;/a&gt; (pleas star that!) but actually there is no reason to not accept it, it does not change anything in core, it does not affect anythign around, is something that if explicitly set, enable something that might be specified like that in ES6 in any case so together with all harmony flags and stuff usable when you run &lt;code&gt;d8&lt;/code&gt; or &lt;code&gt;node&lt;/code&gt;, what could possibly go wrong?&lt;br/&gt;Let me hope, at least, this is not a conspiracy against my mental sanity ... and &lt;a href="https://code.google.com/p/v8/issues/detail?id=2645"&gt;if you star it&lt;/a&gt; it might go in before node 1 is released, thank you! &lt;/p&gt;&lt;img width="200" src="http://ragefaces.s3.amazonaws.com/50420321ae7c705166000001/sooo-cute.png"/&gt; &lt;p&gt;sad thing is, Zepto patch was not affecting Zepto performance or logic, neither was breaking things.&lt;br/&gt;Same thing was for node.js, so I started doubting JS community is able to be proactive when it comes to decisions made somewhere else and for the community.&lt;br/&gt;Developers are pragmatic, they use what's available at that time. If this means create a standard out of it, JavaScript will be anarchy and not a language anymore.&lt;br/&gt;And this, my friend, is unfortunately a specifications circle that is not bringing only good things to the JavaScript as your favorite programming language. &lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/138919135615567944/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=138919135615567944" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/138919135615567944" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/138919135615567944" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/oSWlt6puPHs/the-proto-comic.html" title="The __proto__ Comic" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/the-proto-comic.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-20953429774341730</id><published>2013-04-21T00:26:00.001+02:00</published><updated>2013-04-21T02:02:06.804+02:00</updated><title type="text">Playing With V8 Native And JavaScript</title><content type="html">&lt;p&gt;What my &lt;a href="http://en.wikipedia.org/wiki/Don_Quixote"&gt;Don Quixote&lt;/a&gt; like &lt;a href="http://webreflection.blogspot.com/2013/04/a-journey-to-v8-objectsetproto-native.html"&gt;adventure&lt;/a&gt; against &lt;code&gt;__proto__&lt;/code&gt; gave me, if nothing, is a better understanding about how &lt;a href="https://code.google.com/p/v8/"&gt;V8 engine&lt;/a&gt; internals work and how to bind JavaScript to native and vice-versa. &lt;/p&gt; &lt;h4&gt;Please Note&lt;/h4&gt;&lt;p&gt;Nobody told me anything I've written in this article is true. These are all assumptions &lt;a href="https://code.google.com/p/v8/issues/detail?id=2645"&gt;after pushing a patch to V8&lt;/a&gt; and learning by mistakes, compilation errors, and "&lt;em&gt;code around reading&lt;/em&gt;", done in a couple of hours so apologies in advance if some term or some concept is not perfectly and deeply explained.&lt;br/&gt;Let's start with this! &lt;/p&gt;  &lt;h3&gt;JavaScript In JavaScript&lt;/h3&gt;&lt;p&gt;This was kinda surprising to me, almost the whole ECMAScript is implemented in JavaScript itself.&lt;br/&gt;In few words, what &lt;em&gt;V8&lt;/em&gt; does is not something like &lt;a href="https://developer.mozilla.org/en-US/docs/Rhino"&gt;Rhino&lt;/a&gt;, reimplementing the whole language via a statically compiled one as Java is in Rhino case, &lt;em&gt;V8&lt;/em&gt; is rather &lt;em&gt;the compiler&lt;/em&gt; for the specific ES syntax, following an example ... &lt;/p&gt;  &lt;h3&gt;JSON In JavaScript&lt;/h3&gt;&lt;p&gt;It's funny when we compare in jsperf &lt;a href="http://jsperf.com/json-vs-jquery-json/2"&gt;json2 vs native vs jQuery.json vs json3&lt;/a&gt; etc etc, knowing that &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/json.js"&gt;V8 native JSON&lt;/a&gt; is 90% JavaScript, isn't it? &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;// just a chunk/example from V8 JSON&lt;br /&gt;function JSONParse(text, reviver) {&lt;br /&gt;  var unfiltered = %ParseJson(TO_STRING_INLINE(text));&lt;br /&gt;  if (IS_SPEC_FUNCTION(reviver)) {&lt;br /&gt;    return Revive({'': unfiltered}, '', reviver);&lt;br /&gt;  } else {&lt;br /&gt;    return unfiltered;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Above snippet is simply a compact one with few things non common in Javascript: &lt;code&gt;%PrefixedFunctions()&lt;/code&gt;, and &lt;code&gt;UPPERCASE_FUNCTIONS()&lt;/code&gt;.&lt;br/&gt;These could or could not be bound in any V8 JavaScript files and we can see these JS files are those that will create the JS environment we are going to use but let's see how those special things work, OK? &lt;/p&gt;  &lt;h3&gt;Interoperation Between C++ And JavaScript&lt;/h3&gt;&lt;p&gt;&lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/runtime.cc"&gt;runtime.cc&lt;/a&gt; and &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/runtime.h"&gt;runtime.h&lt;/a&gt; files are dedicated to, as the name suggests, runtime JavaScript calls into C++ world.&lt;br/&gt;The &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/runtime.js"&gt;runtime.js&lt;/a&gt; files contains instead many JS functions used internally to satisfy ECMAScript specifications but not exposed to the outer world.&lt;br/&gt;Bear in mind latter is not the only file that has not exposed JavaScript, while everything that will go out is defined at bootstrap, as you would expect, per each global context (here why two sandboxes have different native constructors) and you can find it in the &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/bootstrapper.cc#829"&gt;bootstrapper.cc&lt;/a&gt; file.&lt;br/&gt;Scroll a bit, and you'll see how all known Array, String, Boolean, etc, are initialized, while in &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/array.js#1483"&gt;array.js&lt;/a&gt; you can see how the prototype is created: it's again a mix of native and JavaScript, passing though macros! &lt;/p&gt;  &lt;h4 id="RUNTIME_FUNCTION"&gt;How To RUNTIME_FUNCTION&lt;/h4&gt;&lt;pre class="code"&gt;&lt;br /&gt;RUNTIME_FUNCTION(&lt;br /&gt;  // return type, for JS interaction&lt;br /&gt;  // will be a MaybeObject* one&lt;br /&gt;  MaybeObject*,&lt;br /&gt;&lt;br /&gt;  // the exposed %DoNotExposeProtoSetter()&lt;br /&gt;  // function in the hidden JS world&lt;br /&gt;  // behind the user available scene&lt;br /&gt;  Runtime_DoNotExposeProtoSetter&lt;br /&gt;) {&lt;br /&gt;  // isolate pointer is necessary to access&lt;br /&gt;  // heap and all JS types in C++&lt;br /&gt;  // even true or false are a specific type&lt;br /&gt;  // we cannot return true directly, as example&lt;br /&gt;  // or the type won't match&lt;br /&gt;  NoHandleAllocation ha(isolate);&lt;br /&gt;  // in this case, returning true or false&lt;br /&gt;  // does not require allocation or new objects&lt;br /&gt;  // we can simply use what's already in the heap&lt;br /&gt;  return FLAG_expose_proto_setter ?&lt;br /&gt;    // this is a flag defined at d8 launch,&lt;br /&gt;    // I'll go there too&lt;br /&gt;    isolate-&gt;heap()-&gt;false_value() :&lt;br /&gt;    isolate-&gt;heap()-&gt;true_value();&lt;br /&gt;    // returns a JS false or a JS true on&lt;br /&gt;    // %DoNotExposeProtoSetter() invocation&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Above function is the same I've used for the patch, it does not accept a thing, it checks a generic program flag and returns true or false accordingly.&lt;br/&gt;As every developer with a bit of C background knows, when a function is declared, it should be defined in the file header too, so here the runtime.h declaration: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;  /* __proto__ Setter */ \&lt;br /&gt;  F(DoNotExposeProtoSetter, 0, 1) \&lt;br /&gt;  \&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;F&lt;/code&gt; is the common shortcut for &lt;code&gt;RUNTIME_FUNCTION_LIST_ALWAYS_N&lt;/code&gt; while the first argument is the length of accepted arguments, &lt;code&gt;-1&lt;/code&gt; if unknown or dynamic.&lt;br/&gt;The second argument seems to be a default for all functions, stick with &lt;code&gt;1&lt;/code&gt; and things gonna be fine. &lt;/p&gt; &lt;h4&gt;Dealing With JS Objects&lt;/h4&gt;&lt;p&gt;My patch has a quite simplified signature, if you are aiming to accept and/or return objects, you should do things in a slightly different way, here an example: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;// function call :-)&lt;br /&gt;RUNTIME_FUNCTION(MaybeObject*, Runtime_Call) {&lt;br /&gt;  // required to handle the current function scope&lt;br /&gt;  HandleScope scope(isolate);&lt;br /&gt;  // arguments are checked runtime, always&lt;br /&gt;  ASSERT(args.length() &gt;= 2);&lt;br /&gt;  int argc = args.length() - 2;&lt;br /&gt;  CONVERT_ARG_CHECKED(JSReceiver, fun, argc + 1);&lt;br /&gt;  // the `this` context :-)&lt;br /&gt;  Object* receiver = args[0];&lt;br /&gt;&lt;br /&gt;  // If there are too many arguments,&lt;br /&gt;  // allocate argv via malloc.&lt;br /&gt;  const int argv_small_size = 10;&lt;br /&gt;  // now you know, functions with more than 10 args&lt;br /&gt;  // are slower :-)&lt;br /&gt;  Handle&amp;lt;Object&gt; argv_small_buffer[argv_small_size];&lt;br /&gt;  // ...&lt;br /&gt;&lt;br /&gt;  // in case it needs to throw an error ...&lt;br /&gt;  bool threw;&lt;br /&gt;  Handle&amp;lt;JSReceiver&gt; hfun(fun);&lt;br /&gt;  Handle&amp;lt;Object&gt; hreceiver(receiver, isolate);&lt;br /&gt;&lt;br /&gt;  // the result, could be undefined too,&lt;br /&gt;  // which is a type indeed&lt;br /&gt;  Handle&amp;lt;Object&gt; result =&lt;br /&gt;      // note, threw passed by reference&lt;br /&gt;      Execution::Call(hfun, hreceiver, argc, argv,&lt;br /&gt;      &amp;threw, true);&lt;br /&gt;&lt;br /&gt;  // do not return anything if there was an error&lt;br /&gt;  if (threw) return Failure::Exception();&lt;br /&gt;&lt;br /&gt;  // eventually, we got a function.call()&lt;br /&gt;  return *result;&lt;br /&gt;  // don't you feel a bit like "f**k yeah" ?&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;I've removed some extra loop for &lt;code&gt;malloc&lt;/code&gt; but basically that's the lifecycle of a JavaScript call invocation. &lt;/p&gt;  &lt;h3&gt;What About Macros&lt;/h3&gt;&lt;p&gt;&lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/macros.py#90"&gt;macros.py&lt;/a&gt; contains some (I believe) highly optimized and target specific (x86, x64, arm) function, able to use &lt;code&gt;%_CPlusPlus()&lt;/code&gt; functions, and containing most common/used functions across all JavaScript APIs such &lt;code&gt;IS_UNDEFINED(obj)&lt;/code&gt;.&lt;br/&gt;It also contains many constants used here and there such &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/macros.py#57"&gt;common date numbers&lt;/a&gt;: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;const HoursPerDay      = 24;&lt;br /&gt;const MinutesPerHour   = 60;&lt;br /&gt;const SecondsPerMinute = 60;&lt;br /&gt;const msPerSecond      = 1000;&lt;br /&gt;const msPerMinute      = 60000;&lt;br /&gt;const msPerHour        = 3600000;&lt;br /&gt;const msPerDay         = 86400000;&lt;br /&gt;const msPerMonth       = 2592000000;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Dunno you, but I find myself often writing similar variables so I wonder if we should simply have them as public static &lt;code&gt;Date&lt;/code&gt; properties ... never mind ... &lt;/p&gt; &lt;h3&gt;d8 Options And Flags&lt;/h3&gt;&lt;p&gt;To complete my journey into V8, I had to set a &lt;code&gt;--expose-proto-setter&lt;/code&gt; flag into &lt;code&gt;d8&lt;/code&gt;, which is the command line tool or the dll what you'll have after a successful build of the V8 project. &lt;/p&gt;&lt;p&gt;&lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/flag-definitions.h#143"&gt;flag-definitions.h&lt;/a&gt; is basically all you need to define a runtime flag providing a decent description that will show up if you &lt;code&gt;d8 --help&lt;/code&gt;:  &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;DEFINE_bool(&lt;br /&gt;  // the flag name&lt;br /&gt;  // d8 --expose_proto_setter&lt;br /&gt;  // OR&lt;br /&gt;  // d8 --expose-proto-setter&lt;br /&gt;  // is the same&lt;br /&gt;  expose_proto_setter,&lt;br /&gt;  // the default value&lt;br /&gt;  false,&lt;br /&gt;  // the flag description, better if meaningful ...&lt;br /&gt;  "exposes ObjectSetProto though __proto__ descriptor.set")&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In order to access that flag in runtime, do not forget to prefix it as &lt;code&gt;FLAG_expose_proto_setter&lt;/code&gt;.&lt;br/&gt;Remember, even a simple value as boolean is cannot be handled like that in JS so check again &lt;a href="#RUNTIME_FUNCTION"&gt;the RUNTIME_FUNCTION example&lt;/a&gt;. &lt;/p&gt; &lt;h3&gt;Building V8&lt;/h3&gt;&lt;p&gt;There is a V8 page specific for this task, all I can add here is that &lt;code&gt;make x64.release&lt;/code&gt; is the fastest way to have a &lt;code&gt;./out/x64/release/d8&lt;/code&gt; executable and start playing, at least in most common/modern PCs or Macs. &lt;/p&gt; &lt;h3&gt;And That's All Folks!&lt;/h3&gt;&lt;p&gt;I know it does not seem much, but this article covers: &lt;ol&gt;  &lt;li&gt;how to define a launch-time flag for d8&lt;/li&gt;  &lt;li&gt;how to interact with C++ bindings for JS code&lt;/li&gt;  &lt;li&gt;how to optimize some macro function&lt;/li&gt;  &lt;li&gt;how to understand magic V8 JS syntax&lt;/li&gt;  &lt;li&gt;how to manipulate, create, change, augment, natives and their prototypes&lt;/li&gt;&lt;/ol&gt;In few words with these steps anyone could write her/his own version of JavaScript, relying in a robust, extremely fast, and cross platform engine, able to also &lt;a href="http://php.net/manual/en/book.v8js.php"&gt;interact with PHP&lt;/a&gt; or other languages.&lt;br/&gt;Bear in mind I am not suggesting anyone out there should start subfragmenting V8, I am sayng that if you need a very specific thing in the environment for a very specific project, you should not be scared by changing what you need and you can also help V8 to be better trying changes directly without just filing bugs: isn't this what Open Source is good for too? &lt;/p&gt;&lt;p&gt;I hope you enjoyed this post, have a nice day! &lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/20953429774341730/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=20953429774341730" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/20953429774341730" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/20953429774341730" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/TYRbYIivEXY/playing-with-v8-native-and-javascript.html" title="Playing With V8 Native And JavaScript" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/playing-with-v8-native-and-javascript.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-3261577299378020654</id><published>2013-04-19T07:14:00.000+02:00</published><updated>2013-04-20T21:09:02.056+02:00</updated><title type="text">A Journey To V8 ObjectSetProto Native Function</title><content type="html">&lt;h3&gt;Update ^_^&lt;/h3&gt;&lt;p&gt;whatever story you are interested about in this post, one is that &lt;a href="https://code.google.com/p/v8/issues/detail?id=2645"&gt;I've proposed a patch to V8 engine&lt;/a&gt; (please star it so it gets in faster) to accept a &lt;code&gt;--expose-proto-setter&lt;/code&gt; flag at runtime able to expose the proper &lt;code&gt;__proto__&lt;/code&gt; setter so that &lt;a href="https://github.com/joyent/node/pull/5341"&gt;my node JS pull request&lt;/a&gt; could start warning modules using &lt;code&gt;__proto__&lt;/code&gt; instead of &lt;code&gt;Object.setPrototypeOf(target, proto)&lt;/code&gt;.&lt;br/&gt;What can I say ... open source is beautiful, you can potentially patch everything you want for anything you need ... even behind stubborn, politics, or decisions nobody agreed on :P&lt;br/&gt;Now back to the original post ... &lt;/p&gt;&lt;hr/&gt; &lt;p&gt;first thing: I write HTML manually in the textarea instead of Markdown, yeah!!!&lt;br/&gt;Why? 'cause nobody on the internet moves fast ... really, no-bloody-body!&lt;br/&gt;so ... back to manual tags writing instead of broken meaningless layout created via magic html editor ... yeeeeeeah! &lt;/p&gt; &lt;h3&gt;The Story ...&lt;/h3&gt;&lt;p&gt;I know this is getting boring and annoying, and I swear I wish I could say it's the last post but every day there's something more and this story is getting both entertaining and ridiculous!&lt;br/&gt;I gonna tell you &lt;em&gt;how I ended up blocked in Zepto.js repository&lt;/em&gt;, and how the rest of reasonable developers are acting instead.&lt;br/&gt;This time, the experiment, is me reporting this story and nothing else. I give you links, I give you facts! &lt;/p&gt;&lt;p&gt;Quick note: &lt;a href="https://twitter.com/benvie/status/324742083447517184"&gt;they keep telling me I should let it go&lt;/a&gt;, but "&lt;i&gt;I cannot sleep anymore&lt;/i&gt;" because of this so here my attempt to describe the whole story! Have a coffee, some new tab link to click and dig into, and please, &lt;strong&gt;please&lt;/strong&gt;, keep reading ... also because you might realize ... &lt;/p&gt;&lt;h3&gt;It's Not Just Me !&lt;/h3&gt;&lt;p&gt;&lt;a href="http://blog.izs.me/"&gt;Isaac Z. Schlueter&lt;/a&gt;, the man behind &lt;strong&gt;node.js&lt;/strong&gt;, &lt;a href="https://twitter.com/izs/status/322370738495582210"&gt;twitted this&lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;a href="https://twitter.com/littlecalculist"&gt;@littlecalculist&lt;/a&gt; So, why hasn't that been removed in favor of Object.setPrototypeOf? Got a link to discussions, or a shorthand version? &lt;/blockquote&gt;&lt;p&gt;The conversation keeps going and &lt;a href="https://twitter.com/littlecalculist/status/322385297885261825"&gt;has one conclusion&lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;a href="https://twitter.com/izs"&gt;@izs&lt;/a&gt; one-line fix: delete Object.prototype.__proto__; // put this in a module called "raygun-neutralizer" :) &lt;/blockquote&gt;&lt;p&gt;Ha ha ha .. so funny the future of JavaScript comes with a &lt;em&gt;foot-raygun&lt;/em&gt; included, don't you think? ^_^ &lt;/p&gt; &lt;h3&gt;V8 *Is* Based On An Object.setPrototypeOf Equivalent&lt;/h3&gt;&lt;p&gt;Breaking news, uh? The &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/v8natives.js#1330"&gt; internal ObjectSetProto&lt;/a&gt; function simply wraps exactly what I've proposed in &lt;a href="https://mail.mozilla.org/listinfo/es-discuss"&gt;es-discuss&lt;/a&gt; as &lt;code&gt;Object.setPrototypeOf(target, proto)&lt;/code&gt;.&lt;br/&gt;In V8 internals represented as &lt;code&gt;return %SetPrototype(this, obj);&lt;/code&gt;&lt;br/&gt;So here the first thing: the engine of miracles needs such power but &lt;em&gt;we, stupid JavaScripters&lt;/em&gt;, how do we dare! &lt;/p&gt; &lt;h3&gt;A Poisoned __proto__&lt;/h3&gt;&lt;p&gt;Not only this is &lt;a href="https://gist.github.com/WebReflection/5370050"&gt;the less consistent&lt;/a&gt; and the most ridiculous property ever introduced in Javascript, this is also &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/v8natives.js#390"&gt;intentionally poisoned as broken&lt;/a&gt; in Google engine.&lt;br/&gt;These are a couple of quotes in my last attempt to make people reasonable in es-discuss, the first one is from &lt;a href="http://infrequently.org/"&gt;Alex Russell&lt;/a&gt;, in &lt;a href="https://mail.mozilla.org/pipermail/es-discuss/2013-April/029710.html"&gt;this reply&lt;/a&gt;: &lt;/p&gt;&lt;blockquote&gt;Assuming "this property" is __proto__, that ship sailed in V8 a long ago and there's zero chance of it ever being removed. It they want to remove it, they can simply fork V8 or ask for a build flag for it. &lt;/blockquote&gt;&lt;p&gt;Not only this is alarming me, as V8 incapable of making changes if considered dangerous as security problems would be, but turned also out that Alex was wrong since today &lt;code&gt;__proto__&lt;/code&gt; is configurable so you can delete it..&lt;br/&gt;.. and all you need to do, after forking, is to &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/v8natives.js#390"&gt;build putting a comment here&lt;/a&gt;. &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;set: desc.getSet(),// === ObjectSetProto ? ObjectPoisonProto&lt;br /&gt;                   // : desc.getSet(),&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;That's it, after that &lt;strong&gt;you can have both &lt;code&gt;__proto__&lt;/code&gt; and a usable descriptor of it&lt;/strong&gt;.&lt;br/&gt;At this point, after a line change in V8 source code, all &lt;em&gt;node.js&lt;/em&gt; could do to have a better environment is to do this during the sturtup: &lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;(function(setPrototypeOf){&lt;br /&gt;  if (setPrototypeOf in Object) return;&lt;br /&gt;  var set = Object.getOwnPropertyDescriptor(&lt;br /&gt;    Object.prototype, '__proto__'&lt;br /&gt;  ).set;&lt;br /&gt;  Object.defineProperty(&lt;br /&gt;    Object,&lt;br /&gt;    setPrototypeOf,&lt;br /&gt;    {&lt;br /&gt;      enumerable: false,&lt;br /&gt;      configurable: true,&lt;br /&gt;      value: function setPrototypeOf(target, proto) {&lt;br /&gt;        set.call(target, proto);&lt;br /&gt;        return target;&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  );&lt;br /&gt;  // TA-DAAAAAAA!!!&lt;br /&gt;  delete Object.prototype.__proto__;&lt;br /&gt;  // problem solved&lt;br /&gt;}('setPrototypeOf'));&lt;br /&gt;&lt;br /&gt;// example&lt;br /&gt;var a = {},&lt;br /&gt;    b = Object.setPrototypeOf({}, a);&lt;br /&gt;&lt;br /&gt;a.isPrototypeOf(b); // true!&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Above scenario does not look like so hard to implement, isn't it Brendan?&lt;br/&gt;However, another concern was about &lt;cite&gt;all npm modules will be broken&lt;/cite&gt; without considering node has versioning so that no, not a single npm will be broken and updated modules could easily swap to this new API maintaining the environment nice, still fast, and clean! &lt;/p&gt;&lt;p&gt;&lt;strong&gt;Moreover&lt;/strong&gt;, the &lt;code&gt;Object.setPrototypeOf&lt;/code&gt; equivalent, called &lt;code&gt;ObjectSetProto&lt;/code&gt; and wrapping &lt;code&gt;%SetPrototype(this, proto)&lt;/code&gt; in V8, &lt;em&gt;is used to set all &lt;code&gt;__proto__&lt;/code&gt; properties&lt;/em&gt;, &lt;a href="https://code.google.com/p/v8/source/browse/trunk/src/v8natives.js#1365"&gt;how cool is that?!&lt;/a&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;br /&gt;InstallGetterSetter($Object.prototype, "__proto__",&lt;br /&gt;    ObjectGetProto, /* ARE YOU READY???? */ ObjectSetProto);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In few words, my proposal is naturally part of the language ... uh wait, this specific features has been commented as: &lt;/p&gt;&lt;blockquote&gt;an added, _de novo_ API that no one wants, which is an ambient capability on Object, is bad and it won't happen &lt;/blockquote&gt;&lt;p&gt; ... &lt;a href="https://mail.mozilla.org/pipermail/es-discuss/2013-April/029734.html"&gt;it was here&lt;/a&gt;!&lt;br/&gt;How would any developer want more power under her/his hands ... don't you dare thinking about it! &lt;/p&gt; &lt;h4&gt;A Bit More Background&lt;/h4&gt;&lt;p&gt;&lt;a href="https://brendaneich.com/"&gt;Brendan Eich&lt;/a&gt; excellently summarized with all links &lt;a href="https://mail.mozilla.org/pipermail/es-discuss/2013-April/029723.html"&gt;the story behind this property&lt;/a&gt;.&lt;br/&gt;In few words, &lt;strong&gt;this property has been discussed and nobody wanted it&lt;/strong&gt;.&lt;br/&gt;They better preferred to quickly, dirty, spec it as &lt;em&gt;configurable&lt;/em&gt;, at least, and as non present in &lt;code&gt;Object.create(null)&lt;/code&gt; objects, so that finally some project could directly get rid of it and drop it via&lt;br/&gt;&lt;code&gt;delete Object.prototype.__proto__;&lt;/code&gt;&lt;br/&gt;as mentioned before.&lt;br/&gt;Moreover, this is another quote from Brendan the same es-discuss post: &lt;/p&gt;&lt;blockquote&gt;Because @izs tweeted something you think Node is going to fork V8? Get real! &lt;/blockquote&gt; &lt;h3&gt;... So I Tried To Get Real ...&lt;/h3&gt;&lt;p&gt;The change required to make that possible in V8 is a 10 seconds task, network push a part ... anyway ...  &lt;/p&gt;&lt;p&gt;In &lt;a href="https://dl.dropboxusercontent.com/u/3685/presentations/node-patterns/node-patterns.pdf#page=26"&gt;Isaac&lt;/a&gt; slides you can read at page 26 that: &lt;/p&gt;&lt;blockquote&gt;not developing a language removes a huge burden. Let TC-39 and V8 fight those battles for us! &lt;/blockquote&gt;&lt;p&gt;So I didn't even bother him with this discussion ... I mean, he's doing the right thing: let other specialists solve problems for you so you can focus on something else .. right ?&lt;br/&gt; The reality is that even if I send that patch to V8, they will not accept it, not even if Microsoft will agree as the right direction to promote a better standard!&lt;br/&gt; The parody about this &lt;em&gt;de-facto utopia&lt;/em&gt; is that &lt;strong&gt;all current IE browsers do not support __proto__&lt;/strong&gt;.&lt;br/&gt;IE is desperate to be part of the not finalized yet spec, and this is probably why the &lt;em&gt;leaked version 11&lt;/em&gt; shows &lt;code&gt;__proto__&lt;/code&gt; shenanigans in the wild .. and those specs are not final ...!&lt;br/&gt; &lt;h3&gt;The Very Sad Result Of Thomas Fuchs Reaction&lt;/h3&gt;&lt;p&gt;Since I've been fighting, blogging, and discussing this problem for months, and since many times &lt;a href="https://mail.mozilla.org/pipermail/es-discuss/2012-December/027579.html"&gt;they came back to me or others&lt;/a&gt; saying that: &lt;/p&gt;&lt;blockquote&gt;It wasn't Node.js that drove that -- it was the "mobile (iOS WebKit  first) web" that wanted __proto__ due to libraries such as Zepto. &lt;/blockquote&gt;&lt;p&gt;So &lt;a href="https://mail.mozilla.org/pipermail/es-discuss/2013-March/029326.html"&gt;I've tried to reply at some point&lt;/a&gt; like: &lt;/p&gt;&lt;blockquote&gt;I think zepto is using that to modify runtime NodeList results after querySelectorAll but in any case it was not me saying that __proto__ isn't used already... &lt;/blockquote&gt;&lt;p&gt;The discussion goes on and on until I think &lt;em&gt;one action is better than many words&lt;/em&gt;, right? &lt;/p&gt; &lt;h4&gt;What Allen Wirfs-Brock Said&lt;/h4&gt;&lt;p&gt;The good &lt;a href="https://twitter.com/awbjs"&gt;@awbjs&lt;/a&gt;, who &lt;em&gt;writes ECMAScript Specifications&lt;/em&gt;, took kindly some of his time to reply to my post entitled &lt;a href="http://webreflection.blogspot.com/2013/03/yet-another-reason-to-drop-proto.html"&gt;Yet Another Reason To Drop __proto__&lt;/a&gt;.&lt;br/&gt;This is his comment: &lt;/p&gt;&lt;blockquote&gt;__proto__ wasn't TC39's mistake and &lt;strong&gt;everybody who participates on TC39 is aware of how terrible it is&lt;/strong&gt;.&lt;br/&gt;...&lt;br/&gt;If you want to eliminate __proto__ you will have to eliminate its usage. Write a shim for Object.setPrototypeOf: &lt;br/&gt;... &lt;br/&gt;Then evangelize web developers like crazy to update all their existing deployed code to use this shim instead of directly using __proto__.&lt;br/&gt;... &lt;br/&gt;&lt;strong&gt;Good luck (seriously)&lt;/strong&gt;&lt;/blockquote&gt;&lt;p&gt;Challenge Accepted! ... so &lt;em&gt;here the big drama&lt;/em&gt; ... that Allen "&lt;cite&gt;Good luck (seriously)&lt;/cite&gt;" "benediction" transpiled in my mind as: &lt;/p&gt;&lt;blockquote&gt;What the hack ... what does he mean with "goog luck (seriusly)", that &lt;a href="https://twitter.com/WebReflection/status/324747929992720384"&gt;JavaScript community is made by passive bigot developers that cannot change simple things&lt;/a&gt;?&lt;br/&gt;Of course we are as good developers as those you can find in any other language ... let me demonstrate it describing the situation in a &lt;code&gt;pull request&lt;/code&gt; commit with all tests greens and zero side effects! &lt;/blockquote&gt; &lt;h4&gt;The Community Reaction&lt;/h4&gt;&lt;p&gt;Sure that once described the problem in &lt;a href="https://github.com/madrobby/zepto"&gt;Zepto.js repository&lt;/a&gt;, and I swear &lt;em&gt;never a Zepto.js developer I know ever showed up in es-discuss&lt;/em&gt; or my blog, I've simply &lt;a href="https://github.com/madrobby/zepto/pull/736"&gt;committed a patch&lt;/a&gt; that was tests approved and changing two lines of code promoting &lt;code&gt;Object.setPrototypeOf&lt;/code&gt; instead of &lt;code&gt;__proto__&lt;/code&gt;.&lt;br/&gt;Long story short: &lt;/p&gt;&lt;img src="http://www.3site.eu/images/zepto.png"/&gt;&lt;p&gt;Here the &lt;a href="https://github.com/madrobby/zepto/pull/736#issuecomment-16586703"&gt;Thomas rant&lt;/a&gt;, accusing me of trolling, after (kinda obviously) him not being aware of anything I've been written 'till now: &lt;/p&gt;&lt;blockquote&gt;It's not about not agreeing with you. It's the form of how you imply or directly state that we're, I quote, "passive bigots" and that somehow __proto__ is insecure and "may" be removed and other weasel words that imply that we don't know what we're doing and you're a white knight to rescue us from ourselves.  No, thank you. Please troll someone else. &lt;/blockquote&gt;&lt;p&gt;Now, whatever Thomas thought was good to demonstrate with his reaction, which is simply, in my opinion, "&lt;i&gt;the ball here is mine, nobody plays if I'm pissed off&lt;/i&gt;" ... since he decided to block me from the whole repository, all I could do is to write an answer in &lt;a href="https://gist.github.com/WebReflection/5370050#comment-817849"&gt;the same gist that is describing the current madness behind that property&lt;/a&gt;.&lt;br/&gt;Really Thomas ... what can I say, congrats! &lt;/p&gt; &lt;h4&gt;Thomas, Not Flex Box Again, Please!&lt;/h4&gt;&lt;p&gt;So if IE will spec a document that's still a draft, and just to make for the broken web &lt;code&gt;__proto__&lt;/code&gt; can create, don't blame anyone if IE will implement that as broken as it is now almost spec'd!&lt;br/&gt;Version 9 won't have it and neither 10, the current one in 2013!&lt;br/&gt;If Zepto.js decides IE is not a target browser, this does not mean every library should decide the same!&lt;br/&gt;Isn't one of our duty, as Web developers, to make the Web available to as many people as possible?&lt;br/&gt;jQuery released today version 2 and IE9 and IE10 are supported, as easy as that .. or maybe that was the reason you were so nervous?&lt;br/&gt;If Zepto wants to shoot in its foot saying &lt;code&gt;__proto__&lt;/code&gt; or nothing .. deal with that, you have less targets there and of course, you know that!&lt;br/&gt; I mean, you better support IE9 and 10 in both Desktop and mobile for a while in any case, don't you?&lt;br/&gt;So since this is the best moment to drop that mistake and go for a better, less obtrusive, pattern, why wouldn't you? &lt;/p&gt; &lt;h3&gt;Update On The Repository&lt;/h3&gt;&lt;p&gt;I am still blocked as if I've been trolling Zepto since ever but at least now Thomas rant is gone and &lt;a href="https://github.com/madrobby/zepto/pull/736#issuecomment-16643307"&gt;there is a statement&lt;/a&gt; from &lt;a href="https://github.com/mislav"&gt;Mislav Marohnić&lt;/a&gt; there I cannot comment but that makes sense for that library, except when it comes to talking about standards, since &lt;strong&gt;__proto__ is not even standard yet&lt;/strong&gt;: &lt;/p&gt;&lt;blockquote&gt;We generally don't pull contributions that don't improve anything. If, for instance, IE implemented the standard API but doesn't support __proto__, we would pull this. But we don't gain anything tangible with this change. We only believe in standards if they actually result in some benefit.  We don't know what the "future of JS" is going to be, so we're making this neat little library that works in the present. When the future of JS arrives, I'm sure we'll adapt accordingly. &lt;/blockquote&gt; &lt;h3&gt;Revelation: Why Is Dropping Proto So Important To Me!!!&lt;/h3&gt;&lt;p&gt;First of all, as I've said, is not just me ...&lt;br/&gt;Secondly, &lt;strong&gt;__proto__ cannot be polyfilled&lt;/strong&gt; while a modern &lt;code&gt;Object.setPrototypeOf&lt;/code&gt; method could be much easier and consistently polyfilled across current browsers.&lt;br/&gt;ES6 specifications aren't going out anny time soon so it's not too late to put a simple method out there able to make the future a bit brighter .. for node.js, for quickly updated browsers, for JavaScript, your favorite programming language.&lt;br/&gt;You don't want too much power in a function? You shouldn't care since the language behind that function has it, so you are just thinking you should be limited, no matter how good or powerful or evil the function will be.&lt;br/&gt;Thanks for reading until here, really appreciated! &lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/3261577299378020654/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=3261577299378020654" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/3261577299378020654" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/3261577299378020654" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/8XSMWdhXUHw/a-journey-to-v8-objectsetproto-native.html" title="A Journey To V8 ObjectSetProto Native Function" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>5</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/a-journey-to-v8-objectsetproto-native.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-4540357782730014030</id><published>2013-04-17T07:36:00.001+02:00</published><updated>2013-04-17T22:42:50.115+02:00</updated><title type="text">How About KISS vs YAGNI ?</title><content type="html">&lt;pre&gt;&lt;br /&gt;I know this might sound silly but I keep having fun writing stuff here&lt;br /&gt;since I've switched to mark down text :P&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### Is This A Natural Conflict ?&lt;br /&gt;If you are wondering what I am talking about I have a very simple example:&lt;br /&gt;the Linux world!  &lt;br /&gt;&lt;br /&gt;In the specific case, file system operations!&lt;br /&gt;&lt;br /&gt;```&lt;br /&gt;# copy a file&lt;br /&gt;cp file1.txt fle2.txt&lt;br /&gt;&lt;br /&gt;# remove a file&lt;br /&gt;rm file1.txt&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### That's A Move File !&lt;br /&gt;Yes, is really that simple! When you move a file you are sure that file has been copied,&lt;br /&gt;it has the new name or the same, if in a different folder, and you can remove the first one.  &lt;br /&gt;OK, OK, if you are a Windows user you might have experienced some lost file in the past&lt;br /&gt;due accidents during the copy such "_not enough space_" I got it, but what if that's because you've been too KISS and not YAGNI?  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### The Software YAGNI Approach&lt;br /&gt;If you can obtain that in a quite simple way, no need to complicate things around.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### The KISS Approach&lt;br /&gt;If everything I need is more than an action, I am not going to like that.  &lt;br /&gt;KISS is also used as concept behind APIs and final, production ready, products.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### The Reality&lt;br /&gt;KISS, however, is probably the most difficult thing ever in programming languages ... &lt;br /&gt;guess why? There's no such thing as **simple** when it come to programming.  &lt;br /&gt;&lt;br /&gt;Actually, the most user-friendly interfaces and interactions, are probably also&lt;br /&gt;the most over engineered so ... you see?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### As Summary&lt;br /&gt;I've no idea if these two approaches, both my favorites, could be confusing and in collision.  &lt;br /&gt;What I know, is that while I was writing this post I've been thinking all the time how to represent&lt;br /&gt;bloody acronyms in Markdown.  &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;It came out that basing my experience with KISS and YAGNI, the best solution I had in mind&lt;br /&gt;was under everybody nose as **JSON**:&lt;br /&gt;`{"KISS":"Keep It Simple, Stupid"}` and `{"YAGNI":"You Ain't Gonna Need It"}`  &lt;br /&gt;&lt;br /&gt;Both have never been mentioned in the [Markdown famous post](http://daringfireball.net/projects/markdown/syntax), something I'd love to contribute updating it!&lt;br /&gt;&lt;/pre&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/4540357782730014030/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=4540357782730014030" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4540357782730014030" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4540357782730014030" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/y4rsqJa_Yn4/how-about-kiss-vs-yagni.html" title="How About KISS vs YAGNI ?" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>5</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/how-about-kiss-vs-yagni.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-1218679999779580015</id><published>2013-04-15T01:27:00.000+02:00</published><updated>2013-04-15T02:38:26.754+02:00</updated><title type="text">Can Deal With Markdown In RSS Readers ?</title><content type="html">&lt;pre&gt;&lt;br /&gt;I've spent some time trying to solve the&lt;br /&gt;[tinydown](https://github.com/WebReflection/tinydown#tinydown)&lt;br /&gt;runtime blogspot parsing and this is the current status:&lt;br /&gt;&lt;br /&gt;  1. desktop browsers are fine&lt;br /&gt;  2. mobile browsers are now fine too&lt;br /&gt;  3. textual browsers lynx like are wonderful now!&lt;br /&gt;  4. browsers without CSS are just fine&lt;br /&gt;  5. browsers without JS are kinda fine too&lt;br /&gt;  6. browsers without CSS and JS are almost fine&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### Your RSS Reader&lt;br /&gt;Most likely, what you are experiencing is something similar to point 5 or,&lt;br /&gt;in the worst case scenario, point 6 of above list.&lt;br /&gt;&lt;br /&gt;Being markdown easy to read as any plain text or book&lt;br /&gt;you are familiar with, can you cope with that for RSS readers?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### As Experiment&lt;br /&gt;Please give you some times to see if this work before answering.&lt;br /&gt;&lt;br /&gt;I realy don't want to piss off my followers so the last option would be&lt;br /&gt;to revert all my changes done in blogger&lt;br /&gt;(or eventually host my blog in my own space)&lt;br /&gt;&lt;br /&gt;One thing I am doing different now, is to preserve a decent amount&lt;br /&gt;of columns before I go into a new line so readers unable&lt;br /&gt;to adopt a `white-space: pre-wrap;` like rendering for feeds&lt;br /&gt;should not be that disturbed anymore ...&lt;br /&gt;&lt;br /&gt;If this is going to work, I think everyone could be happy&lt;br /&gt;about the fact not only you can blog on the cloud without a host,&lt;br /&gt;but what you write can be compatible with emails and everything&lt;br /&gt;that is not HTML enabled ... all plain text, as universal way to&lt;br /&gt;write a human friendly formatted document.&lt;br /&gt;&lt;br /&gt;What do you think? Thanks for your patience!&lt;br /&gt;&lt;/pre&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/1218679999779580015/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=1218679999779580015" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/1218679999779580015" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/1218679999779580015" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/soRbWy-qCHQ/can-deal-with-markdown-in-rss-readers.html" title="Can Deal With Markdown In RSS Readers ?" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>5</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/can-deal-with-markdown-in-rss-readers.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-2618002274157358661</id><published>2013-04-14T03:42:00.003+02:00</published><updated>2013-04-14T07:07:42.215+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="closures" /><category scheme="http://www.blogger.com/atom/ns#" term="flight" /><category scheme="http://www.blogger.com/atom/ns#" term="mixins" /><title type="text">Flight Mixins Are Awesome!</title><content type="html">&lt;pre&gt;&lt;br /&gt;OK, OK, probably is just that I cannot wait to start writing stuff with [tinydown](https://github.com/WebReflection/tinydown#tinydown) but I tweeted about this after last #FlightNight and @angustweets demo ... so here what is behind [Flight](http://twitter.github.io/flight/) mixins choice.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### The Basics&lt;br /&gt;&lt;br /&gt;JavaScript polymorphism is probably one of the best things you can find out there.&lt;br /&gt;&lt;br /&gt;Not kidding, the flexibility that this language offers when it comes to context injection and runtime class definition is simply amazing, as simple, and amazing, is this idea:&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;// most basic example&lt;br /&gt;function enriched() {&lt;br /&gt;  this.method = function () {&lt;br /&gt;    // do stuff&lt;br /&gt;  };&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;Most common books and online documents usually describe above example as a _constructor with privileged methods_.&lt;br /&gt;&lt;br /&gt;Well, that's actually what you get if you `var obj = new enriched();` but that's just one story.&lt;br /&gt;Flight uses a different story, offering alternative methods with better semantics but basically going down to:&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;enriched.call(object);&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### Mixins Baby!&lt;br /&gt;&lt;br /&gt;Using above pattern we can enrich any sort of object with the extra benefit of having a private scope the moment we invoke once the function.&lt;br /&gt;This gives us the opportunity to pass arguments or simply have some private, shared in case of a prototype, variable too.&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;// with arguments and private variables&lt;br /&gt;var Mixin = function Mixin(arg0, argN) {&lt;br /&gt;&lt;br /&gt;  // private variables&lt;br /&gt;  var scoped = {};&lt;br /&gt;&lt;br /&gt;  // privileged methods&lt;br /&gt;  this.method = function method() {&lt;br /&gt;    return scoped;&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  // default properties or initialization&lt;br /&gt;  this.prop = arg0 || 'default';&lt;br /&gt;  this.other = argN;&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// ========================================&lt;br /&gt;&lt;br /&gt;// as Singleton&lt;br /&gt;var singleton = new Mixin;&lt;br /&gt;singleton.method(); // object&lt;br /&gt;singleton.prop; // default&lt;br /&gt;singleton.other; // undefined&lt;br /&gt;&lt;br /&gt;// as prototype with defaults&lt;br /&gt;function Class() {}&lt;br /&gt;Mixin.call(Class.prototype, 'a', 'b');&lt;br /&gt;&lt;br /&gt;var instance1 = new Class,&lt;br /&gt;    instance2 = new Class;&lt;br /&gt;&lt;br /&gt;instance1.method(); // object&lt;br /&gt;instance2.method(); // same object&lt;br /&gt;&lt;br /&gt;// same methods&lt;br /&gt;instance1.method === instance2.method; // true&lt;br /&gt;&lt;br /&gt;// and same object&lt;br /&gt;instance1.method() === instance2.method(); // true&lt;br /&gt;&lt;br /&gt;instance1.prop;  // a&lt;br /&gt;instance1.other; // b&lt;br /&gt;instance2.prop;  // a&lt;br /&gt;instance2.other; // b&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;I have realized how powerful is this simply considering the same approach with prototypes rather than each objects, where methods are of course created per each invokation of the mixin, but that would be indeed absolutely meant and expected.&lt;br /&gt;&lt;br /&gt;What I am saying, is that if you are worried about too many closures and functions generated per each mixin, and you believe your mixin does not need any initialization and methods can be used anywhere without needing a private scope, here all you can do to follow same pattern and save a bit of memory:&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;var Mixin = function(){&lt;br /&gt;  // created once and never again&lt;br /&gt;  function method1(){}&lt;br /&gt;  function method2(){}&lt;br /&gt;  function methodN(){}&lt;br /&gt;  return function () {&lt;br /&gt;    this.method1 = method1;&lt;br /&gt;    this.method2 = method2;&lt;br /&gt;    this.methodN = methodN;&lt;br /&gt;  };&lt;br /&gt;}();&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;I guess that's it, right? But what if we need some sort of initialization per each mixin?&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;### Initializing A Mixing&lt;br /&gt;&lt;br /&gt;There could be things we need to do to ensure the mixin will work as expected per each instance but if we want to coexist out there in the wild, we cannot name methods like `.init()` because of the name clashing if more than a mixin needs to be initialized ... are you following?&lt;br /&gt;&lt;br /&gt;One possible solution that came into my mind is to prefix, with `init` the method, and use the mixin name as suffix.&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;// defaults plus init&lt;br /&gt;var Mixin = function Mixin(dflt0, dfltN) {&lt;br /&gt;&lt;br /&gt;  // private variables&lt;br /&gt;  var scoped = {};&lt;br /&gt;&lt;br /&gt;  // privileged methods&lt;br /&gt;  this.method = function method() {&lt;br /&gt;    return scoped;&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  // avoid multiple mixins name clashing&lt;br /&gt;  // prefix eventual initialization&lt;br /&gt;  // with 'init' plus mixinname&lt;br /&gt;  this.initMixin = function (arg0, argN) {&lt;br /&gt;    this.prop = arg0 || dflt0 || 'default';&lt;br /&gt;    this.other = argN || dfltN;&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;If we follow this approach, we can initialize any mixin we want at any time, e.g.:&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;// explicit initialization&lt;br /&gt;function Class(arg0, argN) {&lt;br /&gt;  this.initMixin(arg0, argN);&lt;br /&gt;}&lt;br /&gt;Mixin.call(Class.prototype, 'a', 'b');&lt;br /&gt;&lt;br /&gt;var instance1 = new Class,&lt;br /&gt;    instance2 = new Class('different');&lt;br /&gt;&lt;br /&gt;instance1.prop;  // a&lt;br /&gt;instance2.prop;  // different&lt;br /&gt;instance1.other; // b&lt;br /&gt;instance2.other; // b&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;Per each instance we can then enrich the constructor so that every mixin that needs to be initialized at that time can be simply call the non clashing method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#### Some Bad Idea You might Have&lt;br /&gt;&lt;br /&gt;Well, it is common in JS to think about `for/in` loops and stuff so that if we know a prefix we can automate tasks ... but in this case I strongly discourage this approach unless you are not 100% sure all mixins initializations support same signature.&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;// *DONT* automatic mixin initialization&lt;br /&gt;function Class() {&lt;br /&gt;  for (var key in this) {&lt;br /&gt;    if (key.slice(0, 4) === 'init') {&lt;br /&gt;      this[key]();&lt;br /&gt;      // or&lt;br /&gt;      this[key].apply(this, arguments);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;In few words, using above technique means coupling mixins with a specific, probably unknown in advance, class signature so it is strongly discouraged.&lt;br /&gt;&lt;br /&gt;Sticking with an explicit mixin initialization is not only faster but able to create any sort of mixin signature.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### Events To The Rescue&lt;br /&gt;&lt;br /&gt;As @kpk reminds me, [Flight is event based](https://twitter.com/kpk/status/323272363053551616) so there's also an easy way to do more after all mixins initialization: `this.after('initialize', fn);`&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### As Summary&lt;br /&gt;&lt;br /&gt;This is only one part of [Flight](http://twitter.github.io/flight/) where [**performance**](http://jsperf.com/mixin-fun/31) were strongly considered for all old and new browsers and this works.&lt;br /&gt;&lt;br /&gt;In an era were many developers are looking for better classes this framework came out with such simple and powerful solution I can't believe I would like to have anything more than this for real apps!&lt;br /&gt;&lt;br /&gt;Enjoy the Flight philosophy and embrace powerful simplicity any time you _A-HA_ it ;)&lt;br /&gt;&lt;/pre&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/2618002274157358661/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=2618002274157358661" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/2618002274157358661" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/2618002274157358661" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/jXCIy2wmFJU/flight-mixins-are-awesome.html" title="Flight Mixins Are Awesome!" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>3</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/flight-mixins-are-awesome.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-5942392604959221230</id><published>2013-04-13T22:24:00.000+02:00</published><updated>2013-04-14T07:07:57.374+02:00</updated><title type="text">tinydown test</title><content type="html">&lt;pre&gt;&lt;br /&gt;OK ladies &amp; gentlemen, time to test [tinydown](https://github.com/WebReflection/tinydown#tinydown) for real.&lt;br /&gt;&lt;br /&gt;### What's New&lt;br /&gt;Well, first of all there are [35 tests](http://webreflection.github.io/tinydown/test/) with nice and/or screwed input and an expected output to complete the library so that any improvement or change will not compromise what's already working.&lt;br /&gt;&lt;br /&gt;The second thing is ... **I am using tinydown now**!&lt;br /&gt;&lt;br /&gt;You can check the source page of this post and see that all it contains is markdown.&lt;br /&gt;&lt;br /&gt;### What's Different&lt;br /&gt;There at least two things different:&lt;br /&gt;&lt;br /&gt;  * it supports more inside the image markup, such youtube and gists&lt;br /&gt;  * it supports twitter handlers, like @WebReflection&lt;br /&gt;  * even if so damn small, like less _than 2Kb_ minzipped, it supports nested blockquotes and lists&lt;br /&gt;&lt;br /&gt;`inline code` is also available together with triple tick syntax and/or tab and spaces so that&lt;br /&gt;&lt;br /&gt;    var code = 'can be be written multiline';&lt;br /&gt;    function alCodeIsPreserved() {&lt;br /&gt;      with(out) {&lt;br /&gt;        alert('problems');&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;I also implemented only here the highlighter for js so&lt;br /&gt;&lt;br /&gt;```js&lt;br /&gt;var code = this.should();&lt;br /&gt;&lt;br /&gt;code.look('gorgeous');&lt;br /&gt;```&lt;br /&gt;&lt;br /&gt;### What's Missing&lt;br /&gt;I don't know yet, I think almost everything I need for blogging should be there.&lt;br /&gt;&lt;br /&gt;The library is compatible with both _node.js_ and web browsers, of course, and if tests are green you should good to use it runtime in your blog too or any other place you think.&lt;br /&gt;&lt;br /&gt;Last but not least, you can **test everything** you want in [this page](http://webreflection.github.io/tinydown/test/test.html live test) and eventually file bugs copying the generated link with your content so it will be straight forward to see what's broken, the why and the how.  &lt;br /&gt;  &lt;br /&gt;Have fun!&lt;br /&gt;&lt;/pre&gt;</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/5942392604959221230/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=5942392604959221230" title="7 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5942392604959221230" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5942392604959221230" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/h8Difa9TVZA/tinydown-test.html" title="tinydown test" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>7</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/tinydown-test.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-5502463749290296921</id><published>2013-04-11T09:37:00.000+02:00</published><updated>2013-04-13T20:56:54.437+02:00</updated><title type="text">Writing Markdown In Blogger</title><content type="html">&lt;h3&gt;Update&lt;/h3&gt;Added tests and support for nested blocks and lists plus youtube video and gists instead of just images.&lt;br/&gt;Here, &lt;a href="http://webreflection.github.io/tinydown/"&gt;have a look at tinydown&lt;/a&gt;, compatible with both node and web. &lt;hr /&gt; Something I've been thinking about since last year &lt;a href="http://js1k.com/2012-love/"&gt;JS1K contest&lt;/a&gt; ... what if I could just write mark down on internet and let crawlers and bots do the math while I just write all I need to?  &lt;h3&gt;tinydown and CloudReflection&lt;/h3&gt;This is basically all it took to create a markdown blogger enabled service as &lt;a href="http://cloudreflection.blogspot.com/2013/04/test.html"&gt;CloudReflection&lt;/a&gt; is.&lt;br/&gt;That's correct, if I edit that post the text I gonna deal with is this one: &lt;pre&gt;&lt;br /&gt;Isn't a tiny markdown parser lovely ?&lt;br /&gt;=====================================&lt;br /&gt;&lt;br /&gt;A markdown is an _easy to read and quite easy to parse_ syntax, ideal for documents&lt;br /&gt;that could be understood by human, and easily converted by machines.&lt;br /&gt;&lt;br /&gt;You are reading markdown now!&lt;br /&gt;-----------------------------&lt;br /&gt;This blogpost is generated on the fly via the proposed script.  &lt;br /&gt;Here the code **example** used for this page:&lt;br /&gt;&lt;br /&gt;    this.onload = function () {&lt;br /&gt;      document.body.innerHTML = tinydown(&lt;br /&gt;        document.body.textContent&lt;br /&gt;      );&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;You can find a very nice guide about [how to markdown here](http://daringfireball.net/projects/markdown/syntax "markdown style guide").&lt;br /&gt;&lt;br /&gt;### What is supported ?&lt;br /&gt;  * headers with = or - notation&lt;br /&gt;  * headers with # notation&lt;br /&gt;  * blockquotes and nested blockquotes&lt;br /&gt;  * ordered and unordered lists&lt;br /&gt;  * images with optional alt ant title&lt;br /&gt;  * inline links with arbitrary title&lt;br /&gt;  * &amp;lt;em&amp;gt; via single asterisks/underscore, or double for &amp;lt;strong&amp;gt; tag&lt;br /&gt;  * inline `code` via `` ` `` backtick&lt;br /&gt;&lt;br /&gt;### What is not supported ? ###&lt;br /&gt;  * paragraphs are missings&lt;br /&gt;  * nested lists and nested markdown inside lists&lt;br /&gt;  * links with references and/or id&lt;br /&gt;  * raw html is not recognized, validated, parsed&lt;br /&gt;&lt;br /&gt;&gt; and just to demonstrate it works&lt;br /&gt;&gt; &gt; this is a nested blockquote example :-)&lt;br /&gt;&gt; have a lovely day&lt;br /&gt;&lt;br /&gt;- - -&lt;br /&gt;&amp;copy; WebReflection&lt;br /&gt;&lt;/pre&gt;This is basically the same text I've used in the &lt;a href="http://www.3site.eu/love/markdown.html"&gt;original demo page&lt;/a&gt;, except links and images are now finalyl supported.&lt;br/&gt;That is going to look exactly the same way you look at it in the following iframe: &lt;iframe width="560" height="480" src="http://cloudreflection.blogspot.com/2013/04/test.html"&gt;&lt;/iframe&gt; &lt;h3&gt;What Else On Blogger Side&lt;/h3&gt;So I had to include a couple of scripts: &lt;ol&gt;&lt;li&gt;&amp;lt;script src='http://webreflection.github.io/tinydown/test/build/tinydown.js'/&amp;gt;&lt;/li&gt;&lt;li&gt;&amp;lt;script src='http://webreflection.github.io/tinydown/test/build/onstuff.js'/&amp;gt;&lt;/li&gt;&lt;/ol&gt;While the first one is the actual &lt;code&gt;tinydown&lt;/code&gt; parser, the second one is just some logic to parse the right content at the right time.&lt;br/&gt;If you want to play with &lt;code&gt;npm install tinydown&lt;/code&gt; parser consider that's just a function and is not as complet eas any other fully compatible markdown parsers ... it just gives me basically everything I need to write my technical posts on blogger ... can I ask anything more? I don't think so!&lt;br/&gt;&lt;strong&gt;Bear in mind&lt;/strong&gt; you should not use same scripts with github external repository file in your production code/blog ... just follow these direction, and stay tuned with the &lt;a href="https://github.com/WebReflection/tinydown#tinydown"&gt;tiny down repository&lt;/a&gt;.</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/5502463749290296921/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=5502463749290296921" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5502463749290296921" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5502463749290296921" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/LgSAK1QDirI/writing-markdown-in-blogger.html" title="Writing Markdown In Blogger" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>6</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/04/writing-markdown-in-blogger.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-1479372886464667495</id><published>2013-03-30T07:07:00.000+01:00</published><updated>2013-03-30T07:07:07.034+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="ES6" /><category scheme="http://www.blogger.com/atom/ns#" term="__proto__" /><category scheme="http://www.blogger.com/atom/ns#" term="mistake" /><title type="text">Yet Another Reason To Drop __proto__</title><content type="html">I know it might sound boring but I really want to put everything down and laugh, or cry harder, the day TC39 will realize &lt;code&gt;__proto__&lt;/code&gt; was one of the most terrible mistakes.&lt;br /&gt; &lt;h3&gt;A Simple Dictionary Attack&lt;/h3&gt;ES6 says that &lt;code&gt;Object.create(null)&lt;/code&gt; should not be affected anyhow from &lt;code&gt;Object.prototype&lt;/code&gt;.&lt;br /&gt;I've already mentioned this in the &lt;a href="http://webreflection.blogspot.com/2013/03/5-reasons-you-should-avoid-proto.html"&gt;5 Reasons You Should Avoid __proto__&lt;/a&gt; post but I forgot to include an example.&lt;br /&gt;You can test all this code with Chrome Canary or Firefox/Nightly and the most basic thing you need to know is this: &lt;pre class="code"&gt;&lt;br /&gt;var n = Object.create(null);&lt;br /&gt;n.__proto__ = {};&lt;br /&gt;&lt;br /&gt;for (var k in n) console.log(k); // __proto__ !!!&lt;br /&gt;Object.keys(n); // ["__proto__"] !!!&lt;br /&gt;&lt;/pre&gt;Got it? So, &lt;code&gt;__proto__&lt;/code&gt; is enumerable in some browser, is not in some other but it will be in all future browsers. Let's go on with examples ... &lt;pre class="code"&gt;&lt;br /&gt;// store values grouped by same key&lt;br /&gt;function hanldeList(key, value) {&lt;br /&gt;  if (!(key in n)) {&lt;br /&gt;    n[key] = [];&lt;br /&gt;  }&lt;br /&gt;  n[key].push(value);&lt;br /&gt;}&lt;br /&gt;// the Dictionary as it is in ES6&lt;br /&gt;var n = Object.create(null);&lt;br /&gt;&lt;/pre&gt;Above code simply does not need to be aware of any problems except in older environment that won't work as expected. If the key is &lt;code&gt;__proto__&lt;/code&gt; instead of storing the value there will be most likely an error or the object will inherit from an empty array the moment &lt;code&gt;n[key] = []&lt;/code&gt; will be executed.&lt;br/&gt;In few words, I believe you don't want to fear security and logic problems every single time you set a property to a generic object ... am I correct?&lt;br /&gt;Now imagine some library such &lt;a href="https://github.com/documentcloud/underscore/blob/master/underscore.js#L84"&gt;underscore.js&lt;/a&gt;, has the most common and generic way to create an object from another one, copying properties ...  &lt;pre class="code"&gt;&lt;br /&gt;function copy(obj) {&lt;br /&gt;  var result = {}, key;&lt;br /&gt;  for (key in obj) {&lt;br /&gt;    if (obj.hasOwnProperty(key)) {&lt;br /&gt;      result[key] = obj[key];&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  return result;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// or if you want ... &lt;br /&gt;function extend(a, b) {&lt;br /&gt;  for (var key in b) {&lt;br /&gt;    if (b.hasOwnProperty(key)) {&lt;br /&gt;      a[key] = b[key];&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  return a;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Now guess what happens if you would like to copy or extend that list we had before, where &lt;code&gt;__proto__&lt;/code&gt; will be own property for the &lt;code&gt;n&lt;/code&gt; variable and the loop is not checking the key as it should ... the object &lt;code&gt;a&lt;/code&gt;, or the new one, will automatically extend an Array and break completely its own expected behaviors ^_^&lt;br /&gt;This is &lt;strong&gt;nothing an explicit &lt;code&gt;Object.setPrototypeOf()&lt;/code&gt; could cause&lt;/strong&gt; ... moreover...&lt;br /&gt; &lt;h3&gt;Real World Performance Impact&lt;/h3&gt;Every utility such lo-dash or underscore should now do this kind of check per each loop if these would like to be considered safe: &lt;pre class="code"&gt;&lt;br /&gt;function copy(obj) {&lt;br /&gt;  var result = {}, key;&lt;br /&gt;  for (key in obj) {&lt;br /&gt;    if (&lt;br /&gt;      obj.hasOwnProperty(key) &amp;&amp;&lt;br /&gt;      key !== '__proto__'&lt;br /&gt;    ) {&lt;br /&gt;      result[key] = obj[key];&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  return result;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Now try to investigate in your real-world daily code how many times you change &lt;code&gt;__proto__&lt;/code&gt; compared with how many times you loop over properties ... I &lt;a href="http://jsperf.com/loop-vs-hop-vs-proto"&gt;give you a test case to compare performance&lt;/a&gt; and remember: mobile matters!&lt;br /&gt; &lt;h3&gt;Really Hard To Debug&lt;/h3&gt;Being a special property in the &lt;code&gt;Object.prototype&lt;/code&gt; and not just a function you could wrap and keep under control, in a new scenario where any object could be &lt;code&gt;instanceof&lt;/code&gt; anything at any time, the inability to intercept &lt;code&gt;__proto__&lt;/code&gt; calls and changes before it happens will be a painful experience in terms of debugging ... what was that instance before? Most likely, you'll never know ^_^&lt;br /&gt;It must be said some engine makes that &lt;code&gt;descriptor.set&lt;/code&gt;ter reusable but this is not the case of current V8, as example, neither the case for all mobile browsers out there today.&lt;br /&gt; &lt;h3&gt;A Stubborn Decision&lt;/h3&gt;What's driving me crazy about this property and all problems it brings, is that regardless there is a possible "speccable" &lt;code&gt;Object.setPrototypeOf()&lt;/code&gt; alternative that would not suffer from anything I've described in all these posts, and just as reminder there is already a spec'd and widely available &lt;code&gt;Object.getPrototypeOf()&lt;/code&gt; in ES5, TC39 will go on and make the problem a standardized one ^_^&lt;br /&gt;I haven't been able to reason against them regardless examples and reasons ... but you could have fun trying too before it's too late!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/1479372886464667495/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=1479372886464667495" title="8 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/1479372886464667495" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/1479372886464667495" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/jo-GspSXSHA/yet-another-reason-to-drop-proto.html" title="Yet Another Reason To Drop __proto__" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>8</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/03/yet-another-reason-to-drop-proto.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-7021213354946356019</id><published>2013-03-29T04:07:00.000+01:00</published><updated>2013-03-29T04:15:01.180+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="WeakMap" /><category scheme="http://www.blogger.com/atom/ns#" term="Symbol" /><category scheme="http://www.blogger.com/atom/ns#" term="polyfill" /><title type="text">Simulating ES6 Symbols In ES5</title><content type="html">&lt;a href="https://github.com/dherman/tc39-codex-wiki/blob/master/data/es6/symbols/index.md#symbols"&gt;Symbols&lt;/a&gt;, previously known as &lt;a href="http://wiki.ecmascript.org/doku.php?id=harmony:private_name_objects"&gt;Names&lt;/a&gt;, are a new way to add real private properties to a generic object. &lt;pre class="code"&gt;&lt;br /&gt;// basic Symbol example&lt;br /&gt;var BehindTheScene = (function(){&lt;br /&gt;  var symbol = new Symbol;&lt;br /&gt;&lt;br /&gt;  function BehindTheScene(){&lt;br /&gt;    this[symbol] = {};&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  BehindTheScene.prototype.get = function(k) {&lt;br /&gt;    return this[symbol][k];&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  BehindTheScene.prototype.set = function(k, v) {&lt;br /&gt;    return this[symbol][k] = v;&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  return BehindTheScene;&lt;br /&gt;&lt;br /&gt;}());&lt;br /&gt;&lt;br /&gt;var obj = new BehindTheScene;&lt;br /&gt;&lt;br /&gt;obj.set('key', 123);&lt;br /&gt;&lt;br /&gt;obj.key; // undefined&lt;br /&gt;obj.get('key'); // 123&lt;br /&gt;&lt;/pre&gt;In few words symbol makes possible to attach properties directly without passing through a WeakMap. A similar behavior could be obtained indeed via WeakMaps: &lt;pre class="code"&gt;&lt;br /&gt;// similar WeakMap example&lt;br /&gt;var BehindTheScene = (function(){&lt;br /&gt;  var wm = new WeakMap;&lt;br /&gt;&lt;br /&gt;  function BehindTheScene(){&lt;br /&gt;    wm.set(this, {});&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  BehindTheScene.prototype.get = function(k) {&lt;br /&gt;    return wm.get(this)[k];&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  BehindTheScene.prototype.set = function(k, v) {&lt;br /&gt;    return wm.get(this)[k] = v;&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  return BehindTheScene;&lt;br /&gt;&lt;br /&gt;}());&lt;br /&gt;&lt;br /&gt;var obj = new BehindTheScene;&lt;br /&gt;&lt;br /&gt;obj.set('key', 123);&lt;br /&gt;&lt;br /&gt;obj.key; // undefined&lt;br /&gt;obj.get('key'); // 123&lt;br /&gt;&lt;/pre&gt; &lt;h3&gt;Why Symbols&lt;/h3&gt;To be honest I am not sure but these somehow bring some magic to the object rather than wrapping magic around it, as it is for the WeakMap example, so at least performance should be better ... right? Well, the current &lt;em&gt;shim VS shim&lt;/em&gt; says that &lt;code&gt;indexOf()&lt;/code&gt; is faster than an implicit &lt;code&gt;toString()&lt;/code&gt;: &lt;a href="http://jsperf.com/symbol-vs-weakmap"&gt;check this &lt;strong&gt;test&lt;/strong&gt; out by yourself&lt;/a&gt; ;)&lt;br /&gt;In any case it looks like private symbols will be a better way to go than WeakMap when all we would like to have is a private property. Symbols can be used as Enums too, being unique as any other object is.&lt;br /&gt; &lt;h3&gt;Simulating Symbols In Current ES5 JavaScript&lt;/h3&gt;As easy as this: &lt;pre class="code"&gt;&lt;br /&gt;var Symbol;&lt;br /&gt;if (!Symbol) {&lt;br /&gt;  Symbol = (function(Object){&lt;br /&gt;&lt;br /&gt;    // (C) WebReflection Mit Style License&lt;br /&gt;&lt;br /&gt;    var ObjectPrototype = Object.prototype,&lt;br /&gt;        defineProperty = Object.defineProperty,&lt;br /&gt;        prefix = '__simbol' + Math.random() + '__',&lt;br /&gt;        id = 0;&lt;br /&gt;&lt;br /&gt;    function get(){/*avoid set w/out get prob*/}&lt;br /&gt;&lt;br /&gt;    function Symbol() {&lt;br /&gt;      var __symbol__ = prefix + id++;&lt;br /&gt;      defineProperty(&lt;br /&gt;        ObjectPrototype,&lt;br /&gt;        this._ = __symbol__,&lt;br /&gt;        {&lt;br /&gt;          enumerable: false,&lt;br /&gt;          configurable: false,&lt;br /&gt;          get: get, // undefined&lt;br /&gt;          set: function (value) {&lt;br /&gt;            defineProperty(this, __symbol__, {&lt;br /&gt;              enumerable: false,&lt;br /&gt;              configurable: true,&lt;br /&gt;              writable: true,&lt;br /&gt;              value: value&lt;br /&gt;            });&lt;br /&gt;          }&lt;br /&gt;        }&lt;br /&gt;      );&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    defineProperty(Symbol.prototype, 'toString', {&lt;br /&gt;      enumerable: false,&lt;br /&gt;      configurable: false,&lt;br /&gt;      writable: false,&lt;br /&gt;      value: function toString() {&lt;br /&gt;        return this._;&lt;br /&gt;      }&lt;br /&gt;    });&lt;br /&gt;&lt;br /&gt;    return Symbol;&lt;br /&gt;&lt;br /&gt;  }(Object));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;A very basic example here: &lt;pre class="code"&gt;&lt;br /&gt;var sym = new Symbol;&lt;br /&gt;var o = {};&lt;br /&gt;o[sym]; // undefined&lt;br /&gt;&lt;br /&gt;o[sym] = 123;&lt;br /&gt;console.log(o[sym]); // 123&lt;br /&gt;for (var k in o) {&lt;br /&gt;  console.log(k); // nothing at all&lt;br /&gt;  // there is nothing to for/in&lt;br /&gt;}&lt;br /&gt;delete o[sym]; // true&lt;br /&gt;&lt;/pre&gt;Of course, you can try also the very first example, the one with a shared, private, symbol variable, that will simply work as expected :)&lt;br /&gt;Bear in mind, regardless being a hack, this script does not actually cause any problem to any other script or library you are using today but it needs ES5 compatible browsers such all mobiles plus all desktops and IE9 or greater.</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/7021213354946356019/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=7021213354946356019" title="9 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/7021213354946356019" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/7021213354946356019" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/j8OIMdx0QeM/simulating-es6-symbols-in-es5.html" title="Simulating ES6 Symbols In ES5" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>9</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/03/simulating-es6-symbols-in-es5.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-6294123193993688185</id><published>2013-03-26T23:57:00.000+01:00</published><updated>2013-03-30T07:11:35.197+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Object" /><category scheme="http://www.blogger.com/atom/ns#" term="__proto__" /><title type="text">5 Reasons You Should Avoid __proto__</title><content type="html">&lt;strong&gt;Update&lt;/strong&gt;: when you've done with this post, there's even more in comments and the newer one: &lt;a href="http://webreflection.blogspot.com/2013/03/yet-another-reason-to-drop-proto.html"&gt;Yet Another Reason To Drop __proto__&lt;/a&gt;&lt;hr/&gt; Too many discussions without real outcome about &lt;code&gt;__proto__&lt;/code&gt; magic evilness or feature. It's time to understand why using it is, &lt;em&gt;today&lt;/em&gt;, a bad idea.&lt;br /&gt; &lt;h3&gt;__proto__ Is NOT Standard (yet)&lt;/h3&gt;&lt;strike&gt;TC39 refused to standardize this property because of the amount of problems it brings&lt;/strike&gt;. Apparently will be part of ES6 but is not there yet.&lt;br/&gt;&lt;code&gt;__proto__&lt;/code&gt; is a silent, non spec'd, agreement. What's the problem? Keep reading ;)&lt;br /&gt; &lt;h3&gt;__proto__ Could NOT Be There&lt;/h3&gt;The silent non standard agreement sees &lt;code&gt;__proto__&lt;/code&gt; as &lt;strong&gt;configurable&lt;/strong&gt; property of the &lt;code&gt;Object.prototype&lt;/code&gt;.&lt;br /&gt;As example, try this in some environment: &lt;pre class="code"&gt;&lt;br /&gt;(this.alert || console.warn)(&lt;br /&gt;  delete Object.prototype.__proto__&lt;br /&gt;); // false or true ?&lt;br /&gt;&lt;/pre&gt;The outcome is migrating from &lt;code&gt;false&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt;. As example, current Chrome has a non configurable descriptor, while Canary has a configurable one. Same is for latest node.js, Firefox, and who know who else.&lt;br /&gt;Having a property configurable means &lt;em&gt;you cannot trust it's going to work&lt;/em&gt; because anyone could have decided to remove it ... why ...&lt;br /&gt; &lt;h3&gt;__proto__ Makes null Objects Unpredictables&lt;/h3&gt;Theoretically, this is all you need to create one or more objects that inherits from &lt;code&gt;null&lt;/code&gt;&lt;pre class="code"&gt;&lt;br /&gt;var Dict = Object.create.bind(Object, null);&lt;br /&gt;&lt;br /&gt;var dictionary = Dict();&lt;br /&gt;dictionary[property] = 1;&lt;br /&gt;if (otherProperty in dictionary) {&lt;br /&gt;  // do stuff&lt;br /&gt;}&lt;br /&gt;// or&lt;br /&gt;if (dictionary[someOtherThing]) {&lt;br /&gt;  // do stuff&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;We cannot trust, as example in Chrome, that any property can be set there because if for some reason the property name is &lt;code&gt;__proto__&lt;/code&gt;, that object inheriting null will completely be &lt;em&gt;unusable/screwed&lt;/em&gt;.&lt;br/&gt;Using &lt;code&gt;hasOwnPropertyDescriptor()&lt;/code&gt; is not even an option since objects that inherit from null do not inherit these methods from &lt;code&gt;Object.prototype&lt;/code&gt;.&lt;br /&gt;The extra silent agreement here is that &lt;code&gt;Object.create(null)&lt;/code&gt; should return objects that are not affected anyhow by any property from &lt;code&gt;Object.prototype&lt;/code&gt; and &lt;code&gt;__proto__&lt;/code&gt; ain't any exception!&lt;br /&gt; &lt;h3&gt;__proto__ Is NOT Secure&lt;/h3&gt;Since any bloody object could be modified directly or deeply anywhere in the middle of its prototypal chain, you can consider all your instances somehow exposed to any sort of attack.&lt;br/&gt;Bad news is: &lt;em&gt;you cannot redefine &lt;code&gt;__proto__&lt;/code&gt; to prevent this&lt;/em&gt;, at least you cannot in current version of Chrome and mobile browsers: &lt;pre class="code"&gt;&lt;br /&gt;function ProtoSafe() {}&lt;br /&gt;Object.defineProperty(&lt;br /&gt;  ProtoSafe.prototype,&lt;br /&gt;  '__proto__',&lt;br /&gt;  {&lt;br /&gt;    get: function () {&lt;br /&gt;      return ProtoSafe.prototype;&lt;br /&gt;    },&lt;br /&gt;    set: function () {&lt;br /&gt;      throw 'immutable';&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;strong&gt;Error: cannot redefine property __proto__&lt;/strong&gt;&lt;br /&gt; &lt;h3&gt;__proto__ Influences Your Logic&lt;/h3&gt;This is last point but actually still important. In &lt;em&gt;ES3&lt;/em&gt; it has never been possible to redefine inheritance over an already created instance and this has never been a real problem.&lt;br /&gt;Polymorphism has always been possible through &lt;em&gt;mixins&lt;/em&gt; and borrowed methods but again, no way an object could suddenly be any sort of instance with such lightweight casting unable to ensure any desired behavior.&lt;br /&gt;What I mean, is that using &lt;code&gt;[].slice.call(arguments)&lt;/code&gt; has a meaning: if there is a &lt;code&gt;length&lt;/code&gt; in the used object, create an array with indexes filled from 0 to that length - 1.&lt;br/&gt;This is different from &lt;code&gt;generic.__proto__ = Array.prototype;&lt;/code&gt; because the &lt;code&gt;length&lt;/code&gt; could be missing and the resulted object behavior be unexpected, broken, or again unpredictable.&lt;br /&gt; &lt;h4&gt;Still A Cheap Way To Cast&lt;/h4&gt;This is the only advantage and the reason some library adopted &lt;code&gt;__proto__&lt;/code&gt; without even thinking about it: performance boost, compared to a whole slice, are a win, and specially in mobile and DOM libraries where results are always threat as ArrayLike objects.&lt;br /&gt; &lt;h3&gt;Object.setPrototypeOf(object, proto) To The Rescue!&lt;/h3&gt;In ES5 all &lt;code&gt;Object&lt;/code&gt; things are managed through the &lt;code&gt;Object&lt;/code&gt; constructor so why not having a method in charge of the &lt;code&gt;__proto__&lt;/code&gt; behavior, since &lt;code&gt;Object.getPrototypeOf(object)&lt;/code&gt; is already available?&lt;br /&gt;Here some advantage:&lt;ol&gt;&lt;li&gt;no way a property can destroy an object, the &lt;code&gt;obj[propName]&lt;/code&gt; check against &lt;code&gt;propName !== '__proto__'&lt;/code&gt; won't be needed anymore: performance!&lt;/li&gt;&lt;li&gt;cheap casting still available so &lt;a href="http://jsperf.com/proto-or-slice"&gt;not a performance issue&lt;/a&gt;&lt;/li&gt;&lt;li&gt;standardizing &lt;code&gt;Object.setPrototypeOf(object, proto)&lt;/code&gt; can bring &lt;strong&gt;new possibilities&lt;/strong&gt; such &lt;code&gt;Object.freezePrototype(object)&lt;/code&gt; in order to &lt;strong&gt;ensure immutable inheritance&lt;/strong&gt; when and if needed&lt;/li&gt;&lt;/ol&gt;&lt;script src="https://gist.github.com/WebReflection/5247136.js"&gt;&lt;/script&gt; &lt;br /&gt; &lt;h3 id="cheaper"&gt;A Cheaper Example&lt;/h3&gt;If you want to ensure TC39 will ever consider to drop this property in favor of better methods in the &lt;code&gt;Object&lt;/code&gt;, here what you should stick in your library that is using proto: &lt;pre class="code"&gt;&lt;br /&gt;var setPrototypeOf = Object.setPrototypeOf || function(o, p){&lt;br /&gt;  o.__proto__ = p;&lt;br /&gt;  return o;&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;It's cheap and &lt;em&gt;performance&lt;/em&gt;, again, are &lt;a href="http://jsperf.com/proto-or-slice"&gt;as good as before&lt;/a&gt;!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/6294123193993688185/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=6294123193993688185" title="9 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/6294123193993688185" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/6294123193993688185" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/2_GhVAtaAHY/5-reasons-you-should-avoid-proto.html" title="5 Reasons You Should Avoid __proto__" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>9</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/03/5-reasons-you-should-avoid-proto.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-1590216775702240369</id><published>2013-03-17T02:42:00.001+01:00</published><updated>2013-03-17T02:45:40.247+01:00</updated><title type="text">Some Repo News</title><content type="html">Well, I don't always post about updates, changes, or new repos here, so here a quick and dirty post on things I've been tweaking, creating, or fixing, recently.  &lt;h3&gt;&lt;a href="https://github.com/WebReflection/dom4#dom4"&gt;DOM4&lt;/a&gt;&lt;/h3&gt;This 100% test covered polyfill is awesome! Combined with some basic utility makes DOM manipulation life really easy. As example, this is how you can shuffle last to first one a list of li: &lt;pre class="code"&gt;&lt;br /&gt;var li = document.querySelectorAll('ul.shuffle li');&lt;br /&gt;li[0].before(li[li.length - 1]);&lt;br /&gt;&lt;br /&gt;// or even better!&lt;br /&gt;var ul = li[0].parentNode;&lt;br /&gt;ul.prepend(ul.lastChild);&lt;br /&gt;&lt;/pre&gt;Pretty cool stuff from W3C!  &lt;h3&gt;&lt;a href="https://github.com/WebReflection/experimental"&gt;experimental.js&lt;/a&gt;&lt;/h3&gt;The most compact and easy way to retrieve experimental features, or standardized, now supports CSS prefixes too. &lt;pre class="code"&gt;&lt;br /&gt;var JSkey = experimental(&lt;br /&gt;  window,&lt;br /&gt;  'requestAnimationFrame'&lt;br /&gt;  // optionally explicit, 'js'&lt;br /&gt;);&lt;br /&gt;// JSkey is the string&lt;br /&gt;// webkitRequestAnimationFrame&lt;br /&gt;// mozRequestAnimationFrame&lt;br /&gt;// others too or&lt;br /&gt;// requestAnimationFrame&lt;br /&gt;&lt;br /&gt;// forcing JS assignment&lt;br /&gt;if (!experimental(&lt;br /&gt;  window,&lt;br /&gt;  'requestAnimationFrame',&lt;br /&gt;  true // force assignment&lt;br /&gt;)) {&lt;br /&gt;  window.requestAnimationFrame = function(cb){&lt;br /&gt;    return setTimeout(cb);&lt;br /&gt;  };&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// now available in all browsers&lt;br /&gt;requestAnimationFrame(daFunction);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;var CSSkey = experimental(&lt;br /&gt;  document.documentElement.style,&lt;br /&gt;  'transform',&lt;br /&gt;  'css'&lt;br /&gt;);&lt;br /&gt;// -webkit-transform&lt;br /&gt;// -moz-transform&lt;br /&gt;// or&lt;br /&gt;// transform&lt;br /&gt;&lt;/pre&gt; &lt;h3&gt;&lt;a href="https://github.com/WebReflection/require-updated#require-updated"&gt;require-updated&lt;/a&gt; module&lt;/h3&gt;Have you ever needed a module that updates automatically as soon as it's edited in &lt;em&gt;node.js&lt;/em&gt; world? This module is meant to provide the most recent version of a module, of course if this is required in the wild rather than once at the top of the JS program.  &lt;h3&gt;&lt;a href="https://github.com/WebReflection/polpetta#-polpetta"&gt;polpetta&lt;/a&gt;&lt;/h3&gt;Some minor clean up and some big plan ahead, makes it the very first &lt;em&gt;fully node.js web server&lt;/em&gt; with simplified configurations, as it is now, but extended to stream, gzip, and caching with ETags and all other common techniques to avoid the usage of a web server on top of it at all.&lt;br/&gt;No idea how much this will take but I am willing to provide some good shit by the time node v1 is out, after next, 0.12, release.&lt;br/&gt;If you don't know what is polpetta yet, considered it's the easiest way to have CGI like behavior in node.js in any folder and that it has been tested in all possible environments with excellent performance, even Raspberry PI, pcDuino, RK3066 modules, as well as Amazon server (not in production, I need those adds-on first).&lt;br/&gt;This update is more about telling you that things are being improved and the project is everything but dead and the &lt;em&gt;require-updated&lt;/em&gt; module has been created for polpetta indeed ;-)  &lt;h3&gt;&lt;a href="https://github.com/WebReflection/gitstrap#gitstrap"&gt;gitstrap&lt;/a&gt; environment&lt;/h3&gt;While many keep struggling with node updates and the inability to run grunt, this or that dependency, &lt;em&gt;gitstrap&lt;/em&gt; keeps being slightly improved making my git flow every day easier. Travis, wru tests, a proper Makefile, easy customization, I know I should probably spend a bit more time documenting or describing various "how-to" but I believe if you know very basics about bash and make, you don't need much from me there ;)  &lt;h3&gt;&lt;a href="https://github.com/WebReflection/redefine#redefinejs"&gt;redefine.js&lt;/a&gt;&lt;/h3&gt;Not only a simplified, more secure, and battle-tested utility for ES5 engines (node.js, Rhino, others) and browsers (all mobile plus all desktops but IE8), now a simplified way to create &lt;em&gt;Classes&lt;/em&gt; too.&lt;br/&gt;Bringing the most useful part from the &lt;a href="https://github.com/WebReflection/poo#poojs"&gt;poo.js&lt;/a&gt; experiment, &lt;strong&gt;redefine.js&lt;/strong&gt; now supports &lt;strong&gt;extend&lt;/strong&gt;, to simplify inheritance in a semantic way, &lt;strong&gt;mixin&lt;/strong&gt; as it will be in ES6, &lt;strong&gt;statics&lt;/strong&gt; for constructors properties and public methods, and all other redefine powerful features like lazy property assignment, defaults for descriptors, and all other things needed for a Class based env, when and if needed!  &lt;h3&gt;&lt;a href="https://github.com/WebReflection/circular-json#circularjson"&gt;CircularJSON&lt;/a&gt; Update&lt;/h3&gt;With support for &lt;em&gt;non resolved paths&lt;/em&gt; when the extra flag is passed through &lt;code&gt;.stringify(data[, receiver[, space[, DO_NOT_RESOLVE]]])&lt;/code&gt;.&lt;br/&gt;The result will be similar to other parsers where the circular reference will have simply the word &lt;em&gt;[Circular]&lt;/em&gt; in it.&lt;br/&gt;&lt;br/&gt; You are welcome :) and see you soon!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/1590216775702240369/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=1590216775702240369" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/1590216775702240369" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/1590216775702240369" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/6qFtD_Cq8j0/some-repo-news.html" title="Some Repo News" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/03/some-repo-news.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-5611093164375757065</id><published>2013-03-14T04:11:00.002+01:00</published><updated>2013-03-14T04:14:30.708+01:00</updated><title type="text">Solving Cycles, Recursions, And Circulars References In JSON</title><content type="html">&lt;strong&gt;&lt;a href="https://github.com/WebReflection/circular-json#circularjson"&gt;CircularJSON&lt;/a&gt;&lt;/strong&gt; is my next level take on &lt;a href="https://twitter.com/getify/status/235391046224326656"&gt;@getify thoughts&lt;/a&gt; about &lt;em&gt;recursive-safe&lt;/em&gt; &lt;code&gt;JSON.stringify()&lt;/code&gt; operation, going further than what &lt;a href="https://twitter.com/izs"&gt;@izs&lt;/a&gt; proposed with his &lt;a href="https://github.com/isaacs/json-stringify-safe#json-stringify-safe"&gt;json-stringify-safe&lt;/a&gt; module which aim, and purpose, can be summarized in his reply: &lt;blockquote&gt;This module is useful for the use case I'm using it for. If it's not your cup of tea, well, GOOD NEWS! There are a lot of cups with a lot of different flavors of tea in them.&lt;/blockquote&gt;Thanks man, what you probably don't know is that actually, there are no concrete, safe, performant, solutions to that problem ... oh well, now there is one!  &lt;h3&gt;CircularJSON&lt;/h3&gt;My fully tested, 650 bytes, portable and cross platform solution, is based on same isaacz logic: the usage of &lt;code&gt;JSON.stringify(data, receiver)&lt;/code&gt;&lt;br/&gt;In few words, if you consider safe the native &lt;code&gt;JSON&lt;/code&gt;, you can consider &lt;strong&gt;safe&lt;/strong&gt; &lt;code&gt;CircularJSON&lt;/code&gt; too in &lt;strong&gt;both serialization and deserialization&lt;/strong&gt;.&lt;br/&gt;Despite what you might think about recursive serialization, &lt;strong&gt;there's no magic behind&lt;/strong&gt; and &lt;a href="http://webreflection.github.com/circular-json/test/"&gt;all tests&lt;/a&gt; can prove that &lt;code&gt;CircularJSON&lt;/code&gt; is simply safe and working as you expect.  &lt;h3&gt;How Can Be That Safe&lt;/h3&gt;THe logic behind is based on native JSON behavior where the receiver and the reviver functions are all CircularJSON uses in order to work.&lt;br/&gt;For the end user, &lt;strong&gt;same JSON API&lt;/strong&gt; is preserved and it works as expected so nothing is different, except circular references are recreated during parse operation.&lt;br/&gt;Once again, &lt;strong&gt;not a rewritten parser, neither a RegExp based solution&lt;/strong&gt;, CircularJSON is the simplest solution to the most common circular, recursion, repeated object, problem.  &lt;h3&gt;How About Performance&lt;/h3&gt;This is tricky, and you can test performance via &lt;code&gt;node test/benchmark.js&lt;/code&gt; and compare results in your machines and with your node version.&lt;br/&gt;Generally speaking, performance is about &lt;em&gt;twice as slow&lt;/em&gt; as regular JSON but &lt;em&gt;only with never repeated data&lt;/em&gt;.&lt;br/&gt;That's correct, as soon as there are repeated objects in the serialization and deserialization process, &lt;em&gt;CircularJSON goes faster&lt;/em&gt; until &lt;em&gt;being faster than JSON&lt;/em&gt; when there are more repeated objects in the stream.&lt;br/&gt;I am obviously excluding cycles and circular references from the game since we all know JSON will simply fail, don't we?  &lt;h3&gt;Why Solving Circular References&lt;/h3&gt;First of all, because we are developers. If there are circular references it probably means we needed them, right? As summary, in my opinion, &lt;em&gt;any attempt to get rid of circular references because of serialization is a failure&lt;/em&gt; for the simple fact that once deserialized, we canot have that reference back anymore.&lt;br/&gt;&lt;strong&gt;THere could be cases we need circular references&lt;/strong&gt; and as PHP, as example, solved them since ever through &lt;code&gt;serialize()&lt;/code&gt; and &lt;code&gt;unserialize()&lt;/code&gt; function, we might want to do the same via JavaScript: why not?!  &lt;h3&gt;Do Not Mix Shit!&lt;/h3&gt;While &lt;a href="https://twitter.com/izs/status/311875255272607745"&gt;@izs thinks I am a moron noob&lt;/a&gt;, &lt;a href="https://twitter.com/getify/status/311876630148681729"&gt;Kyle insinuated something could go wrong&lt;/a&gt; ... well, GOOD NEWS IS, &lt;em&gt;they are both wrong as long as you don't use &lt;code&gt;CircularJSON.parse()&lt;/code&gt; with data that has been encoded with &lt;code&gt;JSON.stringify()&lt;/code&gt;&lt;/em&gt; and of course, the same is valid the other way round: do not &lt;code&gt;.parse()&lt;/code&gt; via &lt;code&gt;JSON&lt;/code&gt; what has been encoded via &lt;code&gt;CircularJSON&lt;/code&gt; ... &lt;strong&gt;it's like using JSON to decode PHP serialized strings&lt;/strong&gt; or vice-versa ... you know what I mean?  &lt;h3&gt;Welcome To Other Languages&lt;/h3&gt;As the fact it has been implemented in multiple programming languages helped &lt;a href="https://github.com/WebReflection/JSONH"&gt;JSONH&lt;/a&gt; to be that successful, and before, of course, JSON protocol itself, once many other programming languages in both client and server will be able to be compatible with circular references this project could be more widely adopted, specially to those that do not use &lt;code&gt;node.js&lt;/code&gt; as server side solution.&lt;br/&gt;Long story short, you are welcome, and thank you in advance, for any &lt;i&gt;other language&lt;/i&gt; implementation you might want to push in &lt;a href="https://github.com/WebReflection/circular-json"&gt;this repository&lt;/a&gt;. Enjoy!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/5611093164375757065/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=5611093164375757065" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5611093164375757065" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5611093164375757065" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/pDx3zQMb8aE/solving-cycles-recursions-and-circulars.html" title="Solving Cycles, Recursions, And Circulars References In JSON" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/03/solving-cycles-recursions-and-circulars.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-3630492577482806815</id><published>2013-03-04T01:14:00.000+01:00</published><updated>2013-03-04T01:16:13.187+01:00</updated><title type="text">Breaking Array Extras</title><content type="html">Every now and then somebody comes out with this problem: &lt;blockquote&gt;How do I stop an iteration such &lt;code&gt;forEach()&lt;/code&gt; ? &lt;/blockquote&gt;Well, there are at least a couple of ways to do that ...  &lt;h3&gt;Dropping The Length&lt;/h3&gt;The first tacky way to stop executing a function is to drop the length of the array. Every extra receives the initial ArrayLike object as third parameter so a function like this should be safe enough: &lt;pre class="code"&gt;&lt;br /&gt;function forEachAndBreak(value, i, arr) {&lt;br /&gt;  if (someCondition(value)) {&lt;br /&gt;    arr.length = 0;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;someArray.forEach(forEachAndBreak);&lt;br /&gt;&lt;/pre&gt;Bear in mind, this will affect the initial array too so if this is not desired, a copy is needed: &lt;pre class="code"&gt;&lt;br /&gt;someArray.slice().forEach(forEachAndBreak);&lt;br /&gt;&lt;/pre&gt;&lt;h4&gt;Cons: Still Looping&lt;/h4&gt;Even if this trick works as expected, there is something we don't see behind the scene: the loop is still going on. If you ever wrote some array polyfill, you might have heard that the &lt;code&gt;for&lt;/code&gt; loop should verify that &lt;code&gt;i in arr&lt;/code&gt; is true, before invoking the function or handling the value at that index since the Array might be a sparse one, where some index might be missing. The same happens with native arrays, you might try this and be stuck for a while: &lt;code&gt;Array(0xFFFFFF).forEach(alert)&lt;/code&gt;. It does not matter if that alert will never be called, the engine is looping through the whole length and verifying each index.  &lt;h3&gt;Using Some&lt;/h3&gt;This is the most common way to prevent the problem. &lt;pre class="code"&gt;&lt;br /&gt;[1,2,3].some(function (value, i, arr) {&lt;br /&gt;  alert(i);&lt;br /&gt;  if (value === 2) {&lt;br /&gt;    return true;&lt;br /&gt;  }&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;Above will alert only 0 and 1 and the loop will be terminated as soon as &lt;code&gt;true&lt;/code&gt; is returned. To quickly test this, let's use again that horrible, gigantic, Array ... &lt;pre class="code"&gt;&lt;br /&gt;var a = Array(0xFFFFFF);&lt;br /&gt;a[1] = 2;&lt;br /&gt;a.some(function(v){if(v === 2) return true});&lt;br /&gt;&lt;/pre&gt;You'll notice that this time the return is immediate, there's no reason to wait after the first result.&lt;br/&gt;In few words, &lt;code&gt;Array#some()&lt;/code&gt; is way better than &lt;code&gt;forEach()&lt;/code&gt; in all those situations where we would like to break the loop at any time: we just return &lt;code&gt;true&lt;/code&gt; when we want to, no need to return anything in all other cases. &lt;h4&gt;Array#every() Is NOT The Opposite Same&lt;/h4&gt;THe thing you might confuse about &lt;code&gt;every&lt;/code&gt; is that &lt;em&gt;you always need to return something&lt;/em&gt; while this is not the &lt;code&gt;some()&lt;/code&gt; case. As we have seen, we return only when/if we want to break.  &lt;h3&gt;Finding The Index Or The Value: The Outer Scope Way&lt;/h3&gt;Another common pattern is to use this approach to actually &lt;em&gt;find the index&lt;/em&gt;, something &lt;code&gt;Array#indexOf()&lt;/code&gt; cannot achieve when the condition is more complicated than just a simple &lt;code&gt;===&lt;/code&gt; comparison. Using an external variable can help here: &lt;pre class="code"&gt;&lt;br /&gt;var index;&lt;br /&gt;if (array.some(function (value, i) {&lt;br /&gt;  if (complicatedCheckAgainst(value)) {&lt;br /&gt;    index = i;&lt;br /&gt;    return true;&lt;br /&gt;  }&lt;br /&gt;})) {&lt;br /&gt;  doComplicatedStuffWith(array[index]);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Analogue situation with the value, so that we can directly retrieve what we are looking for if needed. However, this is kinda less common/used pattern since with the index we might &lt;code&gt;splice&lt;/code&gt; or do more operations than just getting the value;  &lt;h3&gt;Finding The Index: The RegExp Way&lt;/h3&gt;This is quite tacky but fast enough and suitable when the extra argument is not used: I am talking about the context. &lt;pre class="code"&gt;&lt;br /&gt;var index = array.some(function (value, i) {&lt;br /&gt;  if (complicatedCheckAgainst(value)) {&lt;br /&gt;    return this.test(i);&lt;br /&gt;  }&lt;br /&gt;}, /\d+/) &amp;&amp; +RegExp['$&amp;'];&lt;br /&gt;if (index !== false) {&lt;br /&gt;  doComplicatedStuffWith(array[index]);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Above pattern can be handy for inline operations: &lt;pre class="code"&gt;&lt;br /&gt;[].some.call(body.childNodes,flagIt,reNum) !== false &amp;&amp;&lt;br /&gt;(body.childNodes[RegExp['$&amp;']].flagged = true);&lt;br /&gt;&lt;/pre&gt;Whenever it makes sense or not, we can reuse that function and that &lt;code&gt;reNum&lt;/code&gt; in different situations and inline, without needing to create an outer variable. Latter point is indeed the main advantage, reusability without knowing the outer scope. This could be achieved creating something similar via a closure, but that would be probably boring...  &lt;h3&gt;Array#findIndex&lt;/h3&gt;It looks like TC39 will talk about a method ilke this too, so here what I believe would be a draft candidate: &lt;pre class="code"&gt;&lt;br /&gt;(function(AP){&lt;br /&gt;AP.findIndex || (&lt;br /&gt;  AP.findIndex = function(fn, self) {&lt;br /&gt;    var $i = -1;&lt;br /&gt;    AP.some.call(this, function(v, i, a) {&lt;br /&gt;      if (fn.call(this, v, i, a)) {&lt;br /&gt;        $i = i;&lt;br /&gt;        return true;&lt;br /&gt;      }&lt;br /&gt;    }, self);&lt;br /&gt;    return $i;&lt;br /&gt;  };&lt;br /&gt;);&lt;br /&gt;}(Array.prototype));&lt;br /&gt;&lt;/pre&gt;Enjoy!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/3630492577482806815/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=3630492577482806815" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/3630492577482806815" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/3630492577482806815" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/C6BBfMRq_Pw/breaking-array-extras.html" title="Breaking Array Extras" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>3</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/03/breaking-array-extras.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-44587960017855454</id><published>2013-02-23T19:47:00.001+01:00</published><updated>2013-02-24T00:02:21.270+01:00</updated><title type="text">An In House, Yep Nope Like, JS Loader</title><content type="html">Two days ago I've submitted &lt;a href="https://gist.github.com/WebReflection/4993437#file-annotated-js"&gt;a JavaScript loader&lt;/a&gt; to &lt;a href="http://www.140byt.es/users/WebReflection"&gt;140byt.es&lt;/a&gt; since this loader, once minified, &lt;strong&gt;fits into 136 bytes&lt;/strong&gt;. The reason the entry is 140 in the site is that I've left on purpose &lt;code&gt;/**/&lt;/code&gt; to easily spot where you should put JS files to load.  &lt;h3&gt;And That's Not It&lt;/h3&gt;Once we have an Array, we have also &lt;code&gt;.concat()&lt;/code&gt;, and once we have concat, we have the ability to decide, inline, what should be in the menu: &lt;pre class="code"&gt;&lt;br /&gt;var&lt;br /&gt;  menu = [].concat(&lt;br /&gt;    // starter&lt;br /&gt;   'onrefusedbeef' in window ?&lt;br /&gt;      'caprese' : 'salami',&lt;br /&gt;    // main course&lt;br /&gt;    (function(window){&lt;br /&gt;      return !!window.bigAppetite;&lt;br /&gt;    }(this)) ?&lt;br /&gt;      [&lt;br /&gt;        'pasta',&lt;br /&gt;        'salad',&lt;br /&gt;        'bred'&lt;br /&gt;      ] :&lt;br /&gt;      'salad',&lt;br /&gt;    // dessert&lt;br /&gt;    ['coockies'].concat(&lt;br /&gt;      this.extraCalories ?&lt;br /&gt;        ['chocolate', 'sour cream'] :&lt;br /&gt;        [] // nothing to add&lt;br /&gt;    )&lt;br /&gt;  )&lt;br /&gt;;&lt;br /&gt;&lt;br /&gt;// check the menu, chef&lt;br /&gt;alert(menu.join("\n"));&lt;br /&gt;&lt;/pre&gt;You can play with different kind of menus, simply polluting the case with whatever i needed. &lt;pre class="code"&gt;&lt;br /&gt;this.bigAppetite = true;&lt;br /&gt;this. onrefusedbeef = null;&lt;br /&gt;this.extraCalories = true;&lt;br /&gt;&lt;/pre&gt;The cute part about &lt;code&gt;.concat()&lt;/code&gt; is the ability to pass empty arrays, when no extra value should be added to the list, just one element at the time, as example strings, or a list of elements, with the ability to create nested list thanks to nested &lt;code&gt;[].concat()&lt;/code&gt;.&lt;br /&gt;In few words, &lt;em&gt;Array#concat() suites perfectly with a list of files to include&lt;/em&gt; &lt;h3&gt;Real JS Use Cases&lt;/h3&gt;Assuming we don't have partial shims in every single file, assuming we want to bootstrap whatever intakes to have a normalized environment, &lt;em&gt;and do nothing otherwise&lt;/em&gt;, here an example: &lt;pre class="code"&gt;&lt;br /&gt;// to loadvar&lt;br /&gt;  OK = [],&lt;br /&gt;  toLoad = OK.concat(&lt;br /&gt;    Object.create ? OK : 'es5-sham.js',&lt;br /&gt;    OK.forEach ? OK : 'es5-shim.js',&lt;br /&gt;    Function.bind ? OK : 'bindOnlyShim.js',&lt;br /&gt;    window.JSON ? OK : 'json2.js',&lt;br /&gt;    [ // library list&lt;br /&gt;      'lib.js',&lt;br /&gt;      'main.js'&lt;br /&gt;    ]&lt;br /&gt;  );&lt;br /&gt;&lt;br /&gt;// check this out&lt;br /&gt;alert(toLoad.join("\n"));&lt;br /&gt;&lt;/pre&gt;In most modern browsers above snippet will alert only main files while in many Android browsers, the list will have &lt;code&gt;Function#bind()&lt;/code&gt; only shim included, since everything else is there so Array extras are not needed. In older browsers we'll have Array extras, only after Object extras so that Array extras could use ES5 way to define extras ... in few words, the key here is to have scripts aware of their own dependencies instead of include partial shims all over and over ... this is because this little loader loads one script per time and this is ideal when scripts are ordered by dependencies.  &lt;h3&gt;All Together&lt;/h3&gt;Here how the script will look like, &lt;em&gt;as last tag in your document body&lt;/em&gt;, in order to have exactly what you need, in exactly the order you need it. &lt;pre class="code"&gt;&lt;br /&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;!-- everything you need --&amp;gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;!function(b){&lt;br /&gt;&lt;br /&gt;// extra functions, test, variables here&lt;br /&gt;// it's a closure !&lt;br /&gt;&lt;br /&gt;function c(){if(d=e.shift())a=b.body.appendChild(b.createElement("SCRIPT")),a.onload=c,a.src=d}var K=[],e=K.concat(&lt;br /&gt;&lt;br /&gt;  Object.create ? K : 'es5-sham.js',&lt;br /&gt;  K.forEach ? K : 'es5-shim.js',&lt;br /&gt;  Function.bind ? K : 'bindOnlyShim.js',&lt;br /&gt;  window.JSON ? K : 'json2.js',&lt;br /&gt;  [ // library list&lt;br /&gt;    'lib.js',&lt;br /&gt;    'main.js'&lt;br /&gt;  ]&lt;br /&gt;&lt;br /&gt;),a,d;c()}(document);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;h4&gt;Best Practices For Best Performance&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;do not repeat mini/partial/shims/polyfills per each file, do not try to make every file stand alone. In this way you serve, and load, only what's needed&lt;/li&gt;&lt;li&gt;decide statically, if necessary, dependencies in a logical order. If a file is shimming everything, and you want to trust that file, put that before any other that might try to put a shim if the library is not under your control so that file will use the already shimmed function you trust. As example, if any library contains a tiny JSON parser, put the official JSON polyfill before that file if needed. Same is for any library that tries to shim Array extras, put es5-shims before, and of course, only if needed&lt;/li&gt;&lt;li&gt;aggregate everything that cannot be left out, unless your library is 2 Mb gzipped, or unless you have lazy loaded stuff ... but for everything else, really, there's no need to serve 100 tiny files, put them together as part of your library&lt;/li&gt;&lt;li&gt;put main app logic a part and forget &lt;code&gt;DOMContentLoaded&lt;/code&gt; or &lt;code&gt;$(window).ready()&lt;/code&gt;, since this tiny loader works when the body and everything else is on the DOM ... did I tell you to put the loader at the very end of the page? :-)&lt;/li&gt;&lt;/ul&gt;Enjoy!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/44587960017855454/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=44587960017855454" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/44587960017855454" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/44587960017855454" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/EC8pm12V3vw/an-in-house-yep-nope-like-js-loader.html" title="An In House, Yep Nope Like, JS Loader" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/02/an-in-house-yep-nope-like-js-loader.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-2118493030956690517</id><published>2013-02-20T07:07:00.001+01:00</published><updated>2013-02-21T07:38:30.479+01:00</updated><title type="text">My Personal Github Flow</title><content type="html">I've created many repositories in my programming history, starting from the good old &lt;a href="http://code.google.com"&gt;Google Code&lt;/a&gt;, passing through Mercurial HG and svn, ending up using on daily basis the awesome &lt;a href="https://github.com/WebReflection"&gt;Github&lt;/a&gt;.&lt;br /&gt;There is something I've spotted every time I've created a new repo, I needed a way to do &lt;em&gt;always the same thing ... but better each time&lt;/em&gt;!&lt;br /&gt;The very latest case is the &lt;a href="https://github.com/WebReflection/caller-of#caller-of"&gt;callerOf utility&lt;/a&gt;, something that small and already demanding usual/common stuff such:&lt;ul&gt;&lt;li&gt;a meaningful and organized structure, instead of files in the wild&lt;/li&gt;&lt;li&gt;an easy way to test for browsers and often &lt;a href="http://nodejs.org"&gt;nodejs&lt;/a&gt; too&lt;/li&gt;&lt;li&gt;a simple build process per each target, able to combine them all at speed light&lt;/li&gt;&lt;li&gt;a linter for those projects that could be widely adopted and linters are so annoying ... where was I ... right ... &lt;/li&gt;&lt;li&gt;thanks to the same folder structure, an already prepared &lt;code&gt;.gitignore&lt;/code&gt;, together with the &lt;code&gt;.npmignore&lt;/code&gt;&lt;/li&gt;&lt;li&gt;a &lt;code&gt;LICENSE.txt&lt;/code&gt; file, in my personal experiments and libraries always &lt;em&gt;Mit Style&lt;/em&gt;&lt;/li&gt;&lt;li&gt;a &lt;code&gt;Makefile&lt;/code&gt; able to help me combining all these tasks&lt;/li&gt;&lt;li&gt;last, but not least, an almost fully prepared, and basic, &lt;code&gt;package.json&lt;/code&gt; file with main info to publish&lt;/li&gt;&lt;li&gt;optionally, the usage of &lt;code&gt;.travis.yaml&lt;/code&gt; for the awesome &lt;a href="https://travis-ci.org"&gt;Travis CI&lt;/a&gt; service&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;About Travis&lt;/h3&gt;Today &lt;em&gt;I've maden a donation&lt;/em&gt; to &lt;a href="https://love.travis-ci.org"&gt;help those guys maintaining the project&lt;/a&gt;. The email as soon as something goes wrong is a great way to be notified about problems. I've worked in many enterprise environment where this is the default, most basic configuration, to be instantly notified and be able to fix ASAP or revert instantly and a free service working all the time doing this for all those Open Source projects cannot be ignored, and applauded from Developers indeed.&lt;br/&gt;All major programming languages are supported plus it's not that difficult to configure and it's based, if node.js is supported, to the simple &lt;code&gt;npm test&lt;/code&gt; command: &lt;strong&gt;awesome&lt;/strong&gt;!&lt;br/&gt;I won't tell you how much I've donated 'cause it does not matter as long as you donate something to these good fellas, right?&lt;br/&gt; &lt;h3&gt;I Might Not Need Travis, But ...&lt;/h3&gt;The basic way I've configured my &lt;code&gt;gitstrap&lt;/code&gt;, this is the silly name I've chosen for the repo with most basic structure, &lt;em&gt;forces me to build and run tests before being able to push&lt;/em&gt;. OK, OK ... is not that if I don't build and run tests I cannot push, I mean, it could simply be the &lt;code&gt;README.md&lt;/code&gt; edited and not necessarily code, but to know if my code/library is working, I necessarily need to &lt;code&gt;make&lt;/code&gt; and, in that case, be sure that everything is green.&lt;br/&gt;In few words, &lt;em&gt;the moment I push some code I am pretty sure Travis CI will be still green&lt;/em&gt; &lt;strong&gt;but&lt;/strong&gt; if something goes wrong with one of the node.js versions, the test, the server, whatever, really, &lt;em&gt;I'll be still notified and able to react&lt;/em&gt;.&lt;br/&gt;The classic scenario is a &lt;em&gt;pull request&lt;/em&gt; proposed without testing, mybe looks good, only Travis will tell you if it really does, right? ... oh well, feel free to enforce whoever sble to edit even online to run tests ... if you manage :)  &lt;h3&gt;What I Think Is Essential&lt;/h3&gt;In my cases these are the most basic dependencies, able to make my workflow &lt;em&gt;freaking fast&lt;/em&gt; and robust enough too.&lt;ul&gt;&lt;li&gt;&lt;a href="https://github.com/WebReflection/wru#wru--javascript-tests-have-never-been-that-easy"&gt;wru testing framework&lt;/a&gt; for node.js and web via &lt;code&gt;make test&lt;/code&gt;, already configured in latter case inside a handy &lt;code&gt;index.html&lt;/code&gt; eventually published via &lt;code&gt;gh-pages&lt;/code&gt; through &lt;code&gt;make pages&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/WebReflection/polpetta#-polpetta"&gt;polpetta&lt;/a&gt;, in order to be able to automate the inclusion of &lt;em&gt;the same test for both web and node.js&lt;/em&gt; in a &lt;code&gt;ctrl+click&lt;/code&gt; and &lt;code&gt;make web&lt;/code&gt; shortcut&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/jshint/jshint/#jshint-a-static-code-analysis-tool-for-javascript"&gt;JSHint&lt;/a&gt; to eventually enforce the usage of a linter, through &lt;code&gt;make hint&lt;/code&gt; shortcut&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/mishoo/UglifyJS#new-uglifyjs2"&gt;UglifyJS&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;All above projects can be simply included in the current folder via &lt;code&gt;make dependencies&lt;/code&gt;, not distributed via &lt;code&gt;npm&lt;/code&gt; since these are not really part of the project, except the test, where in this case a tiny overhead of &lt;em&gt;130Kb for &lt;strong&gt;wru&lt;/strong&gt; testing library&lt;/em&gt; isn't really a problem for anyone, right? :)  &lt;h3&gt;This Is &lt;a href="https://github.com/WebReflection/gitstrap#gitstrap"&gt;gitstrap&lt;/a&gt;&lt;/h3&gt;Really a sort of &lt;em&gt;github boilerplate for JS related projects&lt;/em&gt;, something &lt;a href="https://github.com/WebReflection/gitstrap"&gt;already organized and ready to go&lt;/a&gt;, something you can simply: &lt;pre&gt;&lt;br /&gt;curl -s https://raw.github.com/WebReflection/gitstrap/master/new &gt;~/gitstrap &amp;&amp; bash ~/gitstrap &amp;&amp; rm ~/gitstrap&lt;br /&gt;&lt;/pre&gt;Following &lt;a href="https://github.com/WebReflection/gitstrap#automatic-setup"&gt;instructions here&lt;/a&gt;, or if you prefer a manual installation: &lt;pre&gt;&lt;br /&gt;git clone git://github.com/WebReflection/gitstrap.git project-name&lt;br /&gt;cd project-name&lt;br /&gt;rm -rf .git&lt;br /&gt;make dependencies&lt;br /&gt;git init&lt;br /&gt;git add .&lt;br /&gt;git commit -m "gitstrap in"&lt;br /&gt;git remote add origin git@github.com:yourname/project-name.git&lt;br /&gt;git push -u origin master&lt;br /&gt;&lt;/pre&gt;After this, don't forget to update &lt;code&gt;Makefile&lt;/code&gt; and &lt;code&gt;package.json&lt;/code&gt; with the right name, specially if you are planning to push to npm, as well as the &lt;code&gt;README.md&lt;/code&gt;.&lt;br/&gt;I might decide to automate this procedure too pretty soon and any extra task or contribution will be more than welcome. Right now I think this is enough.  &lt;h3&gt;About Files And Folders&lt;/h3&gt;Right, this is where I explain what the hack is that structure ... let's start from the top:  &lt;h4&gt;build/&lt;/h4&gt;This folder will contain all versions of the same projects, if the project would like to be compatible with &lt;em&gt;nodejs&lt;/em&gt;, &lt;em&gt;web or generic JS engine&lt;/em&gt;, &lt;em&gt;AMD loader&lt;/em&gt; based on define logic and stuff.  &lt;h4&gt;Yes, A Different Automated File!&lt;/h4&gt;After all discussion on "&lt;em&gt;how should a file be to be compatible with all the mess out there&lt;/em&gt;" I've realized that &lt;em&gt;exporting JS is really a matter of env&lt;/em&gt;, so if everything else is more or less the same, why on earth pollute all possible projects with that exporting nonsense? You need AMD? &lt;a href="https://github.com/WebReflection/gitstrap/blob/master/build/main.max.amd.js"&gt;You get AMD&lt;/a&gt; ... You need node.js? &lt;a href="https://github.com/WebReflection/gitstrap/blob/master/build/main.node.js"&gt;You get node.js&lt;/a&gt; ... and same is for &lt;a href="https://github.com/WebReflection/gitstrap/blob/master/build/main.max.js"&gt;generic env&lt;/a&gt;, is really that easy!&lt;br/&gt;Please note that all builds generate a &lt;strong&gt;.max&lt;/strong&gt; version of the file, those I've just linked, and &lt;a href="https://github.com/WebReflection/gitstrap/blob/master/build/main.js"&gt;a minified version too&lt;/a&gt;, with the exception of node.js, since I don't believe in packed server side code that much :-)  &lt;h4&gt;index.html&lt;/h4&gt;This is used to generate the test page in &lt;code&gt;gh-pages&lt;/code&gt;, so that once the &lt;a href="http://webreflection.github.com/gitstrap/"&gt;pages have been generated&lt;/a&gt;, the &lt;a href="http://webreflection.github.com/gitstrap/test/"&gt;test folder&lt;/a&gt; will contain those tests and launched through the &lt;code&gt;index.html&lt;/code&gt; file.  &lt;h4&gt;Makefile&lt;/h4&gt;The most important thing to edit here is the name of the project and the main file, or the list of files to use. These can be different per build, if needed, or just the same for all of them. You decide!  &lt;h4&gt;LICENSE.txt and other files&lt;/h4&gt;Have been explained already :-) Modify the name in the license, modify the license too, if necessary, and that's pretty much it. You need to edit where necessary to go with your own project.  &lt;h4&gt;src/&lt;/h4&gt;Here is where your source files should go. If the build shoul dhave different targets, as example for node or amd, I think is good to prefix or suffix them with these names. The &lt;code&gt;main&lt;/code&gt; used as example is what the project will export, just an empty object.  &lt;h4&gt;template/&lt;/h4&gt;This might look weird but it's actually what will be used, as file, before and after each build. These files could be empty too, it does not really matter, but it's handy to have them to easily generate AMD, node.js exports, or generic closures to use before and after the generic code reused across targets.  &lt;h4&gt;test/&lt;/h4&gt;Here the big deal, where the &lt;code&gt;.test.js&lt;/code&gt; file will be in charge of running &lt;strong&gt;wru&lt;/strong&gt; against whatever test is present in the folder, as long as there is a counter part in the src too. This should make the possibility to test in isolation easier. Bear in mind &lt;em&gt;node.js needs to &lt;code&gt;require()&lt;/code&gt;&lt;/em&gt; but the browser can load things in pieces so both built version and other files will be included and tested, if tests are in place.  &lt;h3&gt;As Summary&lt;/h3&gt;The aim of this repo is to make at least my life easier, and you can see already in all my github repos that the structure is already like this, and every project is a partial clone of the other with tiny improvements over the &lt;code&gt;Makefile&lt;/code&gt; and some automation maybe not necessary anymore, as it was this good old builder &lt;a href="https://github.com/WebReflection/wru/blob/master/builder/JSBuilder.py_deprecated"&gt;once in python&lt;/a&gt;, then &lt;a href="https://github.com/WebReflection/wru/blob/master/builder/JSBuilder.js"&gt;in nodejs&lt;/a&gt;, and finally obsolete in latter repos :)&lt;br/&gt;Have fun with you extra ultra cool best library ever!   </content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/2118493030956690517/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=2118493030956690517" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/2118493030956690517" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/2118493030956690517" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/rw03OxMFv2A/my-personal-github-flow.html" title="My Personal Github Flow" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/02/my-personal-github-flow.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-4187845885450868879</id><published>2013-02-10T09:34:00.000+01:00</published><updated>2013-02-11T19:25:49.869+01:00</updated><title type="text">Jokes A Part ...</title><content type="html">... is really that easy to start from the scratch or abandon everything, but that's not, by any meaning, an evolution, is rather a reboot.&lt;br/&gt;Unfortunately, written software cannot reboot that easily, and we all know that, except few exceptions where is really needed and we call that refactoring!&lt;br/&gt;Refactoring is needed when everything is not under reasonable control or performance anymore, refactoring puts everything on hold until it's completed ... you know that ;)  &lt;h3&gt;Focus On Reality&lt;/h3&gt;We really should never loose focus on what we are really trying to do, really trying to improve, and for who, if needed, and beside our own self thoughts.&lt;br/&gt;If the rest of the world is doing something in a way, we have really few chances to change that way quickly and easily because we decide that way is wrong, right?&lt;br/&gt;We need to be able to &lt;em&gt;propose the best change able to improve that &lt;strong&gt;de-facto reality&lt;/strong&gt;&lt;/em&gt; rather than thinking that we are able to improve everything simply imposing &lt;i&gt;our own superior&lt;/i&gt; reality ... right ? The moment we'll impose blindly our own meaning of "&lt;i&gt;best way ever&lt;/i&gt;", without even analyzing what's good out there, we are doing everything wrong, IMHO!  &lt;h3&gt;Graceful Enhance ... Everything!&lt;/h3&gt;Really, I think this is generally speaking the best way to go on and, probably, &lt;strong&gt;the only way to go&lt;/strong&gt; too, since everything else has historically failed already so ... why try again?&lt;br/&gt;Understand developers needs inside their libraries too, and not only patterns they used, is, as example, a good starting point.&lt;br/&gt;I am expecting this to be a sort of &lt;em&gt;JS improvements constitution&lt;/em&gt; for the most used programming language in the world, accordingly with the biggest open source community, at least in github ...  &lt;h4 id="js-constitution"&gt;For A Better JS Future&lt;/h4&gt;&lt;ol&gt;  &lt;li&gt;do not break what has been widely adopted already, unless that's really bad in terms of security&lt;/li&gt;  &lt;li&gt;try to stick with the already available and standardized syntax, allowing partial or full polyfills because of graceful &lt;i&gt;OS, Environment, Browsers, Engines, whatever!&lt;/i&gt; migration&lt;/li&gt;  &lt;li&gt;involve as many developers as possible (public survey over internal survey) &lt;strike&gt;rather than provide already decided internal decisions based in already decided internal pools nobody ever heard about out there&lt;/strike&gt;&lt;/li&gt;&lt;/ol&gt;Three points, since everything else is reasonable already and done in a good way ... still!  &lt;h4&gt;Why Is This Important&lt;/h4&gt;I think these points are more or less everything I wished following es-discuss mailing list, really ... from time to time, I have experienced these situations, absolutely unexpected: &lt;ol&gt;  &lt;li&gt;ES4 failed because it was braking the web, we have transpilers now, so everyone should use them instead of JS because of new unsupported syntax (transpilers break the web!)&lt;/li&gt;  &lt;li&gt;if that library does that, and everyone likes that, and that library is not the old Prototype.js or another one nobody here heard about, that library is wrong and that behavior should be different&lt;/li&gt;  &lt;li&gt;we don't want internals/private pools saying that what the rest of the world thinks is needed is wrong, we can have a much bigger audience through public surveys.&lt;/li&gt;&lt;/ol&gt;&lt;strike&gt;Latter one was the most frustrating experience, personally speaking, trying to follow and contribute in that mailing list with parallels, private, things behind the scene, I could not stand by since either you are public, being the ML public and telling the world you are, or you are not, and you can have, in that case, all pointless, useless, irrelevant, pools you can think about, without bothering the rest of the world with your results!&lt;/strike&gt;&lt;br/&gt;&lt;br/&gt; &lt;strong&gt;About That, I Apology&lt;/strong&gt; because I know that specific case had, again, best intentions, but my point is that surveys should be public too because if 3 developers cannot represent the entire community, neither can 300 behind the same company, or just a couple. There are many more of us out there, &lt;strong&gt;I'd love to see the possibility to participate every time a decision about an API should be made&lt;/strong&gt;!&lt;br/&gt;&lt;br/&gt; Thank you for listening!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/4187845885450868879/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=4187845885450868879" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4187845885450868879" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4187845885450868879" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/2GcQNGmmErU/jokes-part.html" title="Jokes A Part ..." /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/02/jokes-part.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-4602845436138501681</id><published>2013-02-10T06:40:00.000+01:00</published><updated>2013-02-10T06:57:54.711+01:00</updated><title type="text">JavaScript Modules, Maybe</title><content type="html">So, you might know already, but ES guys are talking these days about modules and things, as usual, went out of control since everyone wants its own best module version, ever!  &lt;h3&gt;Current Status&lt;/h3&gt;Synchronous, asynchronous, AMD, &lt;code&gt;require()&lt;/code&gt; ... apparently &lt;a href="https://twitter.com/indexzero/status/300431421300957184"&gt;these are all right&lt;/a&gt; for some use case, but &lt;a href="https://twitter.com/BrendanEich/status/300433014490546176"&gt;wrong for some other&lt;/a&gt;.&lt;br/&gt;It looks like JS cannot do synchronous modules ... wait what? &lt;blockquote&gt;why browsers can't since browser have synchronous require since the very beginning? &amp;lt;script&amp;gt; tag anybody? &lt;/blockquote&gt;&lt;a href="https://twitter.com/WebReflection/status/300431478888751104"&gt;This was me&lt;/a&gt; after reading few times JS cannot do sync. Turned out, &lt;a href="https://twitter.com/BrendanEich/status/300433739597631488"&gt;sync script is in HTML specs, not JS one&lt;/a&gt;, but wasn't this about JS indeed, where JS on browser never had this real problem and is simply envious of &lt;node&gt;node.js&lt;/code&gt; module loader simplicity?  &lt;h3&gt;How About Facing Reality&lt;/h3&gt;... where in every language, requiring dependencies has always been synchronous because nobody ever cared about that latency, right? And did anyone even bothered using asynchronous file reading to include modules?&lt;br/&gt;Not even &lt;code&gt;node.js&lt;/code&gt; does that, the most async-centric env I personally know!&lt;br/&gt;As summary, since this is a browser only problem, what I would expect is &lt;em&gt;the ability from browsers engine to pause in a non blocking way the client until the file has been loaded&lt;/em&gt;. You know what I mean? F# does that so that's not an impossible reality ...&lt;br/&gt;How cool would that be and how "&lt;em&gt;free from browsers limits&lt;/em&gt;" the specification of the next module loader in a programming language would be?&lt;br/&gt;The answer seems to be that JavaScript is not an HTML/W3C matter but is limited because of HTML/W3C implementors, those browsers ... &lt;br/&gt;&lt;img src="http://i0.kym-cdn.com/photos/images/original/000/131/399/fry.PNG?1307468855" width="380"/&gt;&lt;br /&gt; &lt;h3&gt;It Doesn't Matter, Had Module!&lt;/h3&gt;Developers are concerned that &lt;a href="http://twatlr.com/thread/299628842610458626"&gt;TC39 might not have real use cases&lt;/a&gt; and the funny part is that an evangelist of everything you know about the web as &lt;a href="https://twitter.com/paul_irish"&gt;@paul_irish&lt;/a&gt; is had his self &lt;a href="https://twitter.com/paul_irish/status/300080151927062528"&gt;some concern about TC39 choices&lt;/a&gt; in term of &lt;em&gt;real-world&lt;/em&gt; cases.&lt;br /&gt;&lt;strong&gt;Meanwhile&lt;/strong&gt;, &lt;a href="http://webreflection.blogspot.de/2012/09/a-meaningful-client-side-alternative-to.html"&gt;AMD does not seem to be an answer&lt;/a&gt;, neither &lt;a href="https://twitter.com/BrendanEich/status/300438654835380224"&gt;the preferred choice&lt;/a&gt;, but regardless we have these scenarios: &lt;ul&gt;&lt;li&gt;those who write for the web and go AMD&lt;/li&gt;&lt;li&gt;those who write for node.js and go require&lt;/li&gt;&lt;li&gt;those who will probably add all &lt;a href="https://github.com/umdjs/umd/blob/master/returnExports.js#L39"&gt;this crap&lt;/a&gt; regardless, and with all due respect for the dev who wrote that with best intentions, even if testing only on web or only node.js (and again, the point is not about the snippet but the fact it should be everywhere in the JS world, you got what I mean, I am sure!)&lt;/li&gt;&lt;/ul&gt;In few words, &lt;a href="https://twitter.com/domenic/status/300373615604543488"&gt;Domenic's suspects&lt;/a&gt; are already a reality: &lt;a href="https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-01/jan-31.md#414-module-update"&gt;nobody is even caring/following about what's going on in this discussion&lt;/a&gt;!&lt;br/&gt;Lazy developers will simply realize at some point nothing works anymore and will go strike blaming the corrupted system, the conspiracy agains the World Wide Web, the fact nobody told them it was going to disappear or change even after 5 years of warnings about deprecations in console, etc etc ... right?&lt;br/&gt;Wrong, they'll just use what worked for them 'till that day without problems and they will still think that &lt;em&gt;you should not break what's in already&lt;/em&gt;, which is one of my favorite parts about ES5, the best update ever, if only every browser was there already, it would be a better JS world for everyone, isn't it?  &lt;h3&gt;Decoupling Import From Loading&lt;/h3&gt;How insane would that be? A semantic syntax that works in any platform, no matter how the platform loads stuff, the build process behind, or the fact you might wrap this way and do what you think is best, even improving upfront your static analysis ... right?&lt;br/&gt;So here &lt;a href="https://github.com/WebReflection/remodule/"&gt;a beta repository called remodel&lt;/a&gt;, something you might want to &lt;code&gt;git clone git://github.com/WebReflection/remodule.git&lt;/code&gt; to run eventually &lt;code&gt;node node_modules/wru/node/program.js test/remodule.js&lt;/code&gt; and see that all tests are passing already.&lt;br/&gt; &lt;h4&gt;Wait, What&lt;/h4&gt;So that project is about having &lt;code&gt;import&lt;/code&gt; like syntax available even in ES3 &lt;pre class="code"&gt;&lt;br /&gt;// ES.next modules syntax&lt;br /&gt;import {a} from "something"&lt;br /&gt;&lt;br /&gt;// remodule&lt;br /&gt;imports("a").from("something");&lt;br /&gt;&lt;/pre&gt;You are following, right? &lt;pre class="code"&gt;&lt;br /&gt;// ES.next modules export&lt;br /&gt;module.exports.a = "whatever";&lt;br /&gt;&lt;br /&gt;// remodule&lt;br /&gt;modules("something", {&lt;br /&gt;  a: "whatever"&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;So, kinda yes, the missing part of all this mess is that a module should be able to register itself if we would like to static analyze it and make the logic work everywhere in both sync and async environments, right?  &lt;pre class="code"&gt;&lt;br /&gt;// ES.next modules export&lt;br /&gt;module.exports = {&lt;br /&gt;  what: "ever"&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// remodule&lt;br /&gt;modules("exports", {&lt;br /&gt;  what: "ever"&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;// remodule backward compatible&lt;br /&gt;modules("exports", module.exports = {&lt;br /&gt;  what: "ever"&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;Latter example is about loading that file with current require or without it ... unfortunately modules function should be there but that's easy to fix, right?  &lt;h4&gt;What Else&lt;/h4&gt;&lt;pre class="code"&gt;&lt;br /&gt;modules("test", {&lt;br /&gt;  a: "this is a",&lt;br /&gt;  b: "this is b",&lt;br /&gt;  c: "this is c"&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;With above code, we might be able to export the test module, regardless the position in the filesystem or the package manager, and do funny things such:  &lt;pre class="code"&gt;&lt;br /&gt;var test = imports('*').from('test');&lt;br /&gt;JSON.stringify(test);&lt;br /&gt;// {"a":"this is a","b":"this is b","c":"this is c"}&lt;br /&gt;&lt;/pre&gt;Cool? we just imported whatever the module exported itself ... there's really nothing to worry about, as &lt;a href="https://twitter.com/benvie/status/300373256429527040"&gt;@benvie&lt;/a&gt; might spot out, the &lt;code&gt;this&lt;/code&gt; is safe too, is the exported object. &lt;pre class="code"&gt;&lt;br /&gt;var a = imports('a').from('test');&lt;br /&gt;a; // "this is a"&lt;br /&gt;&lt;/pre&gt;Well, it's straight forward to get that we can import just one thing from a module, right? Behind the scene, the module must be imported once, and never again, but we can grab a property as needed instead of the whole thing, right? ... and more! &lt;pre class="code"&gt;&lt;br /&gt;var arr = imports('a', 'c').from('test');&lt;br /&gt;// same as&lt;br /&gt;var arr = imports(['a', 'c']).from('test');&lt;br /&gt;&lt;br /&gt;// same as, once Array comprehension is in ...&lt;br /&gt;var [a, b] = imports('a', 'c').from('test');&lt;br /&gt;&lt;/pre&gt;We can specify multiple properties out of a single module ... cool, uh? And more! &lt;pre class="code"&gt;&lt;br /&gt;var aliased = imports({&lt;br /&gt;  a: 'A',&lt;br /&gt;  c: 'b'&lt;br /&gt;}).from('test');&lt;br /&gt;&lt;br /&gt;// in a real world scenario ...&lt;br /&gt;var $ = imports({&lt;br /&gt;  jQuery: '$'&lt;br /&gt;}).from('jquery').$;&lt;br /&gt;&lt;/pre&gt;Yep, aliases are there too, so that &lt;a href="https://github.com/WebReflection/remodule/blob/master/test/remodule.js"&gt;you can actually test everything for real in this file&lt;/a&gt;.  &lt;h3&gt;So ...&lt;/h3&gt;what I've done there, is not even in charge of loading synchronously or asynchronously anything ... I mean, that should be your build process in charge of making things work and instantly available once needed, right? I mean, the Web/DOM part, I get it, modal spinners all over instead of a frozen tab so annoying for the user, but why nobody simply came out with a library in charge of this? Why ES6 modules will break browsers, using all those reserved words unusable in older browsers, will break node.js logic, being incompatible with the exported module, and will probably be never adopted in fact by anybody?&lt;br/&gt;I am still dreaming about web improvements where stuff that gets out is what's really needed and most likely already used out there. Improved? Better? Sure! Pointless? No, thank you!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/4602845436138501681/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=4602845436138501681" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4602845436138501681" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4602845436138501681" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/azLg9kIHm38/javascript-modules-maybe.html" title="JavaScript Modules, Maybe" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/02/javascript-modules-maybe.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-5061905278735559509</id><published>2013-02-07T06:53:00.000+01:00</published><updated>2013-02-07T06:53:22.529+01:00</updated><title type="text">JavaScript EventTarget</title><content type="html">This is about the &lt;a href="http://www.w3.org/wiki/DOM/domcore/EventTarget"&gt;W3C EventTarget&lt;/a&gt; interface, something standard in the DOM side, but still confusing in the JavaScript one where &lt;em&gt;EventEmitter&lt;/em&gt; in node.js, or many other kind of constructors, are simply simulating what has been there for years, and standardized across all browser engines.  &lt;h3&gt;Now In JavaScript Too&lt;/h3&gt;Correct, I have implemented, written, and re-writtem this shit so many times that I have decided to "&lt;i&gt;un&lt;/i&gt;officialize" the already, well described, interface.&lt;br/&gt;&lt;br/&gt; So, &lt;strong&gt;&lt;a href="https://github.com/WebReflection/event-target#event-target"&gt;here the repository&lt;/a&gt;&lt;/strong&gt;, something you can install in node via &lt;code&gt;npm install event-target&lt;/code&gt; and checking examples on how to use it. Cool? I hope so :-)&lt;br/&gt;&lt;br/&gt; Only thing that does not make much sense in a non DOM environment is the capture extra argument, something ignored from 90% of the web, something that can be really useful with the DOM but I could not think about any concrete utility in a pure JS world way. Cool thing is: anyone can extend, wrap, or improve, this &lt;code&gt;EventTarget&lt;/code&gt; library: enjoy!  </content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/5061905278735559509/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=5061905278735559509" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5061905278735559509" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/5061905278735559509" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/f2TwHaFy6kc/javascript-eventtarget.html" title="JavaScript EventTarget" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/02/javascript-eventtarget.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-340011960695920788</id><published>2013-02-03T22:56:00.000+01:00</published><updated>2013-02-03T23:08:41.609+01:00</updated><title type="text">Opera Mobile Is The Best Browser!</title><content type="html">I really do not understand why the Web keeps ignoring this browser which is able to provide &lt;strong&gt;the best browsing experience out of old hardware too&lt;/strong&gt;!&lt;br /&gt; It's not me saying that, there are all test you might want to double check or try by yourself. &lt;ul&gt;  &lt;li&gt;Opera Mobile VS Chrome mobile, a browser available only in latest hardware, and Safari Mobile for iOS 6, and we all know how good is the hardware here. &lt;a href="http://html5test.com/compare/browser/ios60/chromemobile/operamobile1210.html"&gt;Here the result&lt;/a&gt;, with Opera Mobile scoring more than anything else&lt;/li&gt;  &lt;li&gt;Hardware Acceleration, something possible on canvas you might want to test in &lt;a href="http://www.3site.eu/map/"&gt;this old prototype of a map&lt;/a&gt;, the same I have presented at &lt;a href="http://webreflection.blogspot.com/2010/10/front-trends-2010-my-talk.html"&gt;Front Trends in 2010&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;multi touches, so that an interaction with more modern UI based on gestures could work without problems. Here the &lt;a href="http://www.3site.eu/jstests/tesla/"&gt;tesla experiment&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;In Android 2.X Too&lt;/h3&gt;This is the part I love the most about this browser ... I mean, &lt;em&gt;if you assume you have best hardware ever under the hood it's easy to be cool&lt;/em&gt;, right?&lt;br /&gt;I am looking at you &lt;em&gt;Chrome and Safari Mobile&lt;/em&gt;, and I am leaving &lt;em&gt;Firefox Mobile&lt;/em&gt; outside this challenge since, unfortunately, it never competed against stock browsers, in terms of performance. They are getting better, and have to, with Firefox OS, but in an Android 2.3 ... not sure where they are :(&lt;br/&gt;I have a Galaxy Ace, an &lt;strong&gt;Android 2.3 phone, that scores with Opera Mobile 406 plus 12 bonus points&lt;/strong&gt;.&lt;br /&gt;Basically, if all web apps out there would support Opera Mobile, &lt;strong&gt;people should not spend more to update their hardware&lt;/strong&gt; because there is a browser that is kicking every other browser asses in term of performance!  &lt;h3&gt;Symbian Too&lt;/h3&gt;Correct, good old NOKIA phones could be up to date without problems simply using Opera Mobile, no need to spend that much to get a Windows Phone there, if the problem is the browser you can have touches and multi touches plus extreme performance boost simply downloading and using by default Opera Mobile: as easy as that!  &lt;h3&gt;Definition Of Best Browser&lt;/h3&gt;A browser that is able to bring to the user every possible modern feature, without requiring HardWare or Operating Systems updates. This would be, in my opinion, the best browser in the world, the missing piece we all have and somehow keep ignoring, in this web scenario.  &lt;h3&gt;Why Is That&lt;/h3&gt;I start thinking Opera Mobile team has a really bad marketing support. I cannot believe &lt;strong&gt;my stock browser scores 200 against 406 in Opera Mobile&lt;/strong&gt; and there's no usage percentage in global stats about this browser if not about the Opera Mini version, a completely different beast?&lt;br/&gt;Wha the hell is going on? Why aren't we all developing for this browser too? It's also the easiest to test since available in many platforms ... so, as summary, when I think about &lt;strong&gt;any HTML5 product that does not support Opera Mobile&lt;/strong&gt; is kinda lame, while if it does not support Opera Mobile at its best, using all features that are available, usually twice as those available by default stock browser and in a really performant way, we should rethink our priorities, also because once again, &lt;strong&gt;this browsers is available in multiple platform so it should be the preferred target, rather than the least considered one&lt;/strong&gt;. This usually means profit too so ... I am just saying, and thank you for listening!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/340011960695920788/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=340011960695920788" title="13 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/340011960695920788" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/340011960695920788" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/F7JHfGRfRZU/opera-mobile-is-best-browser.html" title="Opera Mobile Is The Best Browser!" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>13</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/02/opera-mobile-is-best-browser.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-4762658216081818691</id><published>2013-02-01T18:50:00.000+01:00</published><updated>2013-02-01T18:58:25.531+01:00</updated><title type="text">The Difficult Road To Vine Via Web</title><content type="html">&lt;a href="http://vine.co"&gt;One of the coolest and most rumored app of these days&lt;/a&gt; looked so fun, and conceptually simple, that I could not resist to challenge myself trying to reproduce it via HTML5 and all possible experimental things I know that are working these days for both desktop and mobile.  &lt;h3&gt;Wine&lt;/h3&gt;This is the name I have chosen for this experiment, and this is the very first warning: &lt;em&gt;it does not work as it should, is not the equivalent, it cannot substitute the native App&lt;/em&gt;: too bad, but probably the reason vine team didn't even try to propose such broken experience.  &lt;h3&gt;Well, Something Is Working!&lt;/h3&gt;Guess who's this idiot with a Koala hat in a leaving room:&lt;br /&gt;&lt;br /&gt;&lt;img src="https://raw.github.com/WebReflection/wine/master/wine.png" /&gt;&lt;br /&gt;&lt;br /&gt;That's correct, "&lt;i&gt;it's a me&lt;/i&gt;" through the &lt;a href="https://github.com/WebReflection/wine"&gt;wine&lt;/a&gt; experimental project and a Chrome browser. But let's talk a little bit about technologies I have used, OK? &lt;ul&gt;  &lt;li&gt;&lt;strong&gt;Client&lt;/strong&gt; (in order of dependencies)&lt;ul&gt;    &lt;li&gt;&lt;a href="https://github.com/WebReflection/experimental#experimental"&gt;experimental.js&lt;/a&gt; and &lt;a href="http://webreflection.blogspot.de/2012/03/tweet-sized-queue-system.html"&gt;Queue&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;HTML5 &lt;a href="https://developer.mozilla.org/en-US/docs/WebRTC/navigator.getUserMedia"&gt;getUserMedia({video:true, audio:maybe})&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="https://github.com/mattdiamond/Recorderjs"&gt;Recorderjs&lt;/a&gt; for the &lt;em&gt;maybe&lt;/em&gt; and &lt;em&gt;Canary only&lt;/em&gt; audio stream.&lt;/li&gt;    &lt;li&gt;something else such XMLHttpRequest and FormData, but these aren't important&lt;/li&gt;  &lt;/ul&gt;&lt;/li&gt;  &lt;li&gt;&lt;strong&gt;Server&lt;/strong&gt; (in order of importance)&lt;ul&gt;    &lt;li&gt;&lt;a href="http://nodejs.org"&gt;node.js&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://webreflection.github.com/polpetta/"&gt;polpetta&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://ffmpeg.org"&gt;ffmpeg&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.lcdf.org/gifsicle/"&gt;gifsicle&lt;/a&gt;&lt;/li&gt;  &lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;If you want to know how to install the environment and play with the project, once again, &lt;a href="https://github.com/WebReflection/wine"&gt;the repository&lt;/a&gt; explaining how to :-)  &lt;h3&gt;How Does It Work&lt;/h3&gt;Well, you launch the server, you connect to that page, you press the video up to 6 seconds. If you release your finger or your pointer, it stops recording. when the top bar is filled up, each frame will be rendered as image and sent to the server, together with the audio, where some magic happens and the result is a video in mp4, ogv, and webm formats, plus a nice fallback as animated gif so that every single body can see again those 6 seconds, nice? Now, time to talk about all possible problems I had during its development ...  &lt;h3&gt;Everything You Know About getUserMedia() Is A Lie&lt;/h3&gt;This has been the biggest headache during the creation of this prototype.&lt;br /&gt;All articles I have read, included &lt;a href="http://www.html5rocks.com/en/tutorials/getusermedia/intro/"&gt;this excellent one in HTML5 Rocks&lt;/a&gt;, which is marking the article valid for Opera and Firefox too, do not work ... really, as simple as that: that stuff does not work!&lt;br /&gt; &lt;h4&gt;The Right Way To Attach A Stream&lt;/h4&gt;In my proudly created spaghetti code I ended up with a Frankenstein monster such: &lt;pre class="code"&gt;&lt;br /&gt;function attachStream(media, stream) {&lt;br /&gt;  try {&lt;br /&gt;    // Canary likes like this&lt;br /&gt;    media.src = window.URL.createObjectURL(stream);&lt;br /&gt;  } catch(_) {&lt;br /&gt;    // FF and Opera prefer this&lt;br /&gt;    // I actually prefer this too&lt;br /&gt;    media.src = stream;&lt;br /&gt;  }&lt;br /&gt;  try {&lt;br /&gt;    // FF prefers this&lt;br /&gt;    // I think it should not be needed if the video is autoplay&lt;br /&gt;    // ... never mind&lt;br /&gt;    media.play();&lt;br /&gt;  } catch(_) {}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;So, the most advanced browser is apparently behind the schedule because &lt;a href="http://nightly.mozilla.org"&gt;Firefox Nightly&lt;/a&gt; and &lt;a href="http://www.opera.com/browser/next/"&gt;Opera Next&lt;/a&gt; just refuse to work through the &lt;code&gt;URL.createObject()&lt;/code&gt; approach.&lt;br /&gt;However, I found Firefox behavior a non-sense because of the required &lt;code&gt;play()&lt;/code&gt;, completely against the logic behind the &lt;a href="https://developer.mozilla.org/en-US/docs/HTML/Element/video#Attributes"&gt;autoplay video attribute&lt;/a&gt;.  &lt;h4&gt;Bad News Is ...&lt;/h4&gt; my code ain't gonna work for long time neither, things are changing, so keep reading and smile ^_^  &lt;h4&gt;AudioContext and AudioStream Is Nowhere!&lt;/h4&gt;Correct, another myth of these HTML5 days is the audio stream. Nightly is able to expose it inside the stream but I could not manage to retrieve it and handle buffers in and out. Nightly has also another really annoying problem, the redundancy of the microphone recording the audio itself ... &lt;strong&gt;a noise you'll spot&lt;/strong&gt; if you don't mute manually your computer speakers.&lt;br /&gt;I had to &lt;code&gt;video.muted = true&lt;/code&gt; in order to avoid such disturbing noise, something present in Canary too but if the volume is not 100% is much less easy to reach that point. Canary seems to be more clever here! Opera does not seem to work neither with this audio stuff.&lt;br /&gt;The best one seems to be Apple Safari browser: &lt;a href="http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/PlayingandSynthesizingSounds/PlayingandSynthesizingSounds.html"&gt;nothing works but they have the best documentation&lt;/a&gt;!  &lt;h4&gt;Surely It's Me&lt;/h4&gt;I might have done something wrong, but if browser vendors keep implementing and changing standards behind the scene how can this be developers fault?&lt;br/&gt;Here an example, I ask &lt;cite&gt;how come &lt;a href="http://caniuse.com/stream"&gt;getUserMedia() is so much NOT available&lt;/a&gt;?&lt;/cite&gt;&lt;br/&gt;&lt;a href="https://twitter.com/mtrimpe/status/295997672035328000"&gt;The answer was this one&lt;/a&gt;! &lt;blockquote&gt;Because Microsoft recently scuttled ongoing standardization efforts with a surprisingly valid counterproposal I'm afraid.&lt;/blockquote&gt; &lt;h4&gt;DAFUQ?!&lt;/h4&gt;I love all efforts from Microsoft, Firefox OS, Chrome OS, if any, and all others trying to propose standards ... but I don't understand any vendor that is trying to kill a reasonable one until the best proposed one ever will be rolled out ... I mean, &lt;i&gt;can I haz that meow?&lt;/i&gt; &lt;h3&gt;Until Things Are Usable&lt;/h3&gt;I feel like somebody is having fun screwing standards from time to time and every abandoned proposal that looks good to developers has the same destiny:&lt;ul&gt;  &lt;li&gt;stick forever in some library because in those days, that was the behavior&lt;/li&gt;  &lt;li&gt;make the new proposal not powerful regardless, since it came out of a hybrid, not perfect one, that everyone probably already adopted, as it is for &lt;code&gt;localStorage&lt;/code&gt; and &lt;code&gt;WebSQL&lt;/code&gt;, things that just work as developers need to do more, things still there, just randomly there&lt;/li&gt;  &lt;li&gt;fragmented on the Desktop, fragmented on the mobile more than ever and where &lt;strong&gt;on mobile, updates do not basically exist. On mobile, we keep changing Hardware generations, and not software!&lt;/strong&gt;&lt;br/&gt;iOS here is a partially lovely exception, able to update longer, but my iPad 1 is stuck behind iOS 5.X, you know what I mean ... right ?&lt;/li&gt;&lt;/ul&gt;I really feel &lt;a href="https://twitter.com/codepo8"&gt;Christian Heilmann&lt;/a&gt; when he says that what &lt;a href="http://christianheilmann.com/2013/01/31/flash-is-not-the-enemy-our-lack-of-focus-on-what-is-important-is/"&gt;matters is &lt;em&gt;reachability&lt;/em&gt; and everything else is a futile discussion&lt;/a&gt;.&lt;br /&gt;I probably have same feelings, better summarized, as web developer, in this personal thoughts: &lt;blockquote&gt;It does not matter if it's &lt;code&gt;touchstart&lt;/code&gt; or &lt;code&gt;pointerEventDown&lt;/code&gt; event guys, what's important is that it f*#$!(in works when a person put a finger in his device screen and this person bought that device thinking is touch-able ... YES, THE BROWSER TOO! &lt;/blockquote&gt;Also, because people don't, and should, ever care about software, that's our problem, and should never be people limitation with the hardware and the software they like, they use, they need, they want ... but we keep smiling, right? ^_^  &lt;h3&gt;The Web Has Never Been This Broken&lt;/h3&gt;And this is the beautiful lie behind HTML5: it's utopia that never worked in reality!&lt;br/&gt;Articles and examples that &lt;em&gt;work only for this browser&lt;/em&gt;, the thing we have complained about for years about IE thinking "&lt;cite&gt;dude, if you don't know how to create a site don't write it works only for IE you lamer&lt;/cite&gt;"!&lt;br /&gt;Problem is, we are not going anywhere even on mobile, where guess what, platform fragmentation is growing much more than desktop one. On Desktop we have 3 OS Families, Windows, OSX, and Linux generic distro (I feel you Gentoo, Fedora, Redhat, Ubuntu, Debian, Kubuntu guys ... sorry to group you there).&lt;br/&gt;On mobile, we have newcomers all over so iOS, Android 2.2/1.3/3.0/3.1/4.0/4.0.1/4.1/4.2 and here you have the coolest device ever, and Firefox OS plus that sneaky &lt;strong&gt;&lt;a href="http://www.opera.com/mobile/"&gt;Opera Mobile&lt;/a&gt;, I mean &lt;em&gt;mobile&lt;/em&gt;, not mini, the best, fastest, most updated, browser ever for both Symbian and Android 2.X&lt;/strong&gt;!  &lt;h3&gt;Wasn't This About Wine?&lt;/h3&gt;Right ... you are right, I stop here wining about the fact that indeed, Opera Mobile is the only mobile browser able to work, even in Android 2.3, regardless low performance it just look and feel OK there, so if you want to try this you can try with Opera Mobile and enjoy the project.&lt;br/&gt;&lt;strong&gt;Chrome Mobile doesn't getUserMedia()&lt;/strong&gt;, so doesn't FirefoxOS, neither anything else I could try (come on, you are not trying with a windows phone, right? They killed the current standard proposing something else ... cooler, but more to wait for!).&lt;br /&gt; So, the end of this story is that I have created a project which aim is to simulate a native App, and I miserably failed. &lt;strong&gt;Not because performance were not good&lt;/strong&gt;, since once again &lt;strong&gt;it works via Opera Mobile in my &lt;a href="http://www.gsmarena.com/samsung_galaxy_ace_s5830-3724.php"&gt;Galaxy Ace&lt;/a&gt;&lt;/strong&gt;, an Android 2.3 smartphone really simple, really functional, really usable thanks to a decent battery life due to low hardware specs, so ... again, &lt;strong&gt;it's not a performance issue&lt;/strong&gt;, and you can test it, it's more about mistakes, rush, and wrongly accepted proposal from those that are deciding standards ... for good, sure, but if WebSQL was universally available, cross browser/platform speaking, how much more we, web developers, could have we done?&lt;br/&gt;Think about it, that could have been the best thing ever to build No-SQL concept on top, but never &lt;a href="https://developer.mozilla.org/en-US/docs/IndexedDB"&gt;something like this about IndexedDB&lt;/a&gt;: &lt;blockquote&gt;Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes. &lt;/blockquote&gt; And this after at least 2 years ... now ask yourself honestly if current &lt;code&gt;getUserMedia()&lt;/code&gt; was already available cross browser, how many creative things could have been created already?&lt;br/&gt; &lt;h3&gt;At Least These!&lt;/h3&gt;&lt;ul&gt;  &lt;li&gt;web based alarm systems, video can be captured into canvas, canvas can scan images, canvas can detect suspicious movements comparing diffs between previous image and current one in a place that supposes to be quite&lt;/li&gt;  &lt;li&gt;no need to call the specialist that will install the expensive hardware, the cable, the camera, and everything else, if &lt;a href="https://github.com/felixge/node-ar-drone"&gt;we can program quadcopters via node.js&lt;/a&gt;, JavaScript is good and fast enough to monitor the house, the garage, the entrance, and tell you everywhere you are in the world, what's going on plus, if you need to, it can send you pictures while &lt;i&gt;quadcopting&lt;/i&gt; around :D&lt;/li&gt;  &lt;li&gt;create a Skype like application without needing Skype at all ... OK, Skype offers an amazing service and we cannot even think to compete on web, but still ... &lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;End Of The Rant&lt;/h3&gt;I am pretty sure &lt;a href="https://twitter.com/jeresig"&gt;John Resig&lt;/a&gt;, who's &lt;a href="http://vine.co/v/bJuBQha1e5X"&gt;already using Vine&lt;/a&gt; since the very beginning, would actually agree with this Web situation .. or maybe not, since his &lt;em&gt;story-rock API&lt;/em&gt; main goal was to uniform all this mess ... but should we keep relying third parts API rather than awesome, ultra skilled, exceptional people, in charge of the future of the Web?&lt;br/&gt;&lt;br/&gt; &lt;h3&gt;Anyway, Wine Works With...&lt;/h3&gt;So once you have installed everything, all you have to do is to start &lt;code&gt;polpetta&lt;/code&gt; in that folder and connect through these browser to that address: Chrome Canary, Firefox Nightly, Opera Next, Opera Mobile, or any other browser you think should support this app, and it will not ... keep smiling!!!! ^_^&lt;br /&gt;&lt;br /&gt; Thanks for your understanding, I am developing web mobile since 2009, since Android 1.5, and the thing is: it never got truly better, it just kept changing and fragmenting!&lt;br/&gt;Probably the reason I love my job, and the constant challenge it offers on daily basis but I'd like to do more there ... </content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/4762658216081818691/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=4762658216081818691" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4762658216081818691" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/4762658216081818691" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/StrkFL-LuX8/the-difficult-road-to-vine-via-web.html" title="The Difficult Road To Vine Via Web" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/02/the-difficult-road-to-vine-via-web.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-34454975.post-891461924419918743</id><published>2013-01-30T05:44:00.000+01:00</published><updated>2013-01-31T06:01:46.325+01:00</updated><title type="text">Resurrecting The With Statement</title><content type="html">You might think this must be a joke, well &lt;strong&gt;no&lt;/strong&gt;, &lt;em&gt;this is a partial lie behind the &lt;code&gt;"use strict";&lt;/code&gt; directive.&lt;/em&gt;&lt;br /&gt; &lt;h3&gt;Roots Of The Hack&lt;/h3&gt;&lt;pre class="code"&gt;&lt;br /&gt;// global&lt;br /&gt;"use strict";&lt;br /&gt;&lt;br /&gt;function strict() {&lt;br /&gt;  "use strict"; // top of the function&lt;br /&gt;&lt;br /&gt;  return {&lt;br /&gt;    // invoked inline&lt;br /&gt;    withStrict: function(){&lt;br /&gt;      return this; // undefined&lt;br /&gt;    }(),&lt;br /&gt;&lt;br /&gt;    // invoked inline too&lt;br /&gt;    withoutStrict: Function("return this")()&lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// the test&lt;br /&gt;var really = strict();&lt;br /&gt;&lt;br /&gt;really.withStrict;    // undefined&lt;br /&gt;really.withoutStrict; // global, BOOOOM!&lt;br /&gt;&lt;/pre&gt; &lt;h3&gt;The Good News&lt;/h3&gt;I have been blaming since ever the fact that use strict makes impossible to retrieve the real global object ensuring nobody in the closure redefined &lt;code&gt;window&lt;/code&gt; or &lt;code&gt;global&lt;/code&gt; by accident so that code is more reliable.&lt;br /&gt;Well, now we have the possibility to return it again when it's needed for security reasons or to be sure is the right one. &lt;pre class="code"&gt;&lt;br /&gt;// a classic code for Rhino, node, and Web&lt;br /&gt;var G = typeof window !== "undefined" ? window : global;&lt;br /&gt;// then we need to use G&lt;br /&gt;&lt;br /&gt;// with this hack&lt;br /&gt;var global = Function("return this")();&lt;br /&gt;// that's it, is the window or the global object&lt;br /&gt;&lt;/pre&gt; &lt;h3&gt;The Funny News: With Statement Is Back&lt;/h3&gt;So, we are able to deactivate the &lt;code&gt;"use strict"&lt;/code&gt; directive in the global scope, right?&lt;br/&gt;How about bringing back something that would throw an error otherwise in a strict context as &lt;code&gt;with(){}&lt;/code&gt; is? &lt;pre class="code"&gt;&lt;br /&gt;"use strict";&lt;br /&gt;Function("with({test:123}){ alert(test) }")();&lt;br /&gt;// 123&lt;br /&gt;&lt;/pre&gt;&lt;strong&gt;It Works!!!&lt;/strong&gt; Awesome, we can use a &lt;code&gt;with&lt;/code&gt; statement always be executed through &lt;code&gt;Function&lt;/code&gt; which, differently from &lt;code&gt;eval&lt;/code&gt;, evaluates in the global scope.  &lt;h3&gt;With Great Power Come Great Shenanigans&lt;/h3&gt;The reason number one for abandoning the &lt;code&gt;with(){}&lt;/code&gt; statement is its ambiguity, together with the ability to pollute by mistake the global scope.&lt;br/&gt;However, there were few things impossible to represent without that statement, and few of them have been proposed as &lt;a href="http://blog.mozilla.org/dherman/2011/12/01/now-thats-a-nice-stache/"&gt;the monocle mustache&lt;/a&gt; behavior. &lt;pre class="code"&gt;&lt;br /&gt;array.{&lt;br /&gt;    pop()&lt;br /&gt;    pop()&lt;br /&gt;    pop()&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;path.{&lt;br /&gt;    moveTo(10, 10)&lt;br /&gt;    stroke("red")&lt;br /&gt;    fill("blue")&lt;br /&gt;    ellipse(50, 50)&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;this.{&lt;br /&gt;    foo = 17&lt;br /&gt;    bar = "hello"&lt;br /&gt;    baz = true&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt; &lt;h3&gt;A Mustache Like With statement&lt;/h3&gt;Latter snippet is not able to pollute the global context, neither it changes context, plus it can interact with the outer scope. OK, it is not possible to implement automagically the latter one, but we can still avoid context and global context pollution ensuring a proper &lt;code&gt;this&lt;/code&gt; value, and throwing errors if some variable does not belong to &lt;i&gt;the mustached object&lt;/i&gt;.&lt;br/&gt;How? Reactivating the &lt;code&gt;"use strict";&lt;/code&gt; directive again inside the non strict code: how crazy is that? &lt;pre class="code"&gt;&lt;br /&gt;function With(o) {&lt;br /&gt;  // needs a block, a function&lt;br /&gt;  // can simulate that properly&lt;br /&gt;  return function (f) {&lt;br /&gt;    // deactivate during evaluation the strict directive&lt;br /&gt;    return Function(&lt;br /&gt;      // it is possible to use the with statement now&lt;br /&gt;      "with(this){return(" + ("" + f).replace(&lt;br /&gt;        // but we want to reactivate strict env inside&lt;br /&gt;        "{", "{'use strict';"&lt;br /&gt;      // avoid global context pollution&lt;br /&gt;      // forcing a different this&lt;br /&gt;      ) + ").call(this)}"&lt;br /&gt;    ).call(o);&lt;br /&gt;  };&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;So, let's see compared with previous examples, right ? &lt;pre class="code"&gt;&lt;br /&gt;With(array)(function(){&lt;br /&gt;    pop()&lt;br /&gt;    pop()&lt;br /&gt;    pop()&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;With(path)(function(){&lt;br /&gt;    moveTo(10, 10)&lt;br /&gt;    stroke("red")&lt;br /&gt;    fill("blue")&lt;br /&gt;    ellipse(50, 50)&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;With(this)(function(){&lt;br /&gt;    foo = 17&lt;br /&gt;    bar = "hello"&lt;br /&gt;    baz = true&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;Does it work nested too ? Yes! &lt;pre class="code"&gt;&lt;br /&gt;With({test:{key:"value"}})(function(){&lt;br /&gt;  alert(test); // [object Object]&lt;br /&gt;  With(test)(function(){&lt;br /&gt;    alert(key); // "value"&lt;br /&gt;  });&lt;br /&gt;&lt;br /&gt;  // change the property&lt;br /&gt;  test = 456;&lt;br /&gt;&lt;br /&gt;  // by accident pollute the global scope&lt;br /&gt;  not_defined = "oops?"; // throws an error ^_^&lt;br /&gt;&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;After that, removing the error at the end, the original object would shave the number &lt;code&gt;456&lt;/code&gt; as &lt;code&gt;test&lt;/code&gt; property.&lt;br /&gt;In few words, we can have a &lt;em&gt;secured &lt;code&gt;with(){}&lt;/code&gt; statement behavior&lt;/em&gt; without the possibility to hurt the generic surrounding scope anyhow, except for those death browser without the strict directive, of course :D  &lt;h3&gt;Performance, Use Cases, etc&lt;/h3&gt;Yes, I believe the performance problem we know about that statement is still there, but with less problems to take care due strict behavior and a global environment. I would actually say that performance could be optimized with this technique, because no scope and context are implicit or modifiable anyhow, but I am not the right person to tell you what the hell happens in that case inside a JS engine :D&lt;br /&gt;Use cases might be tests related, DOM related, since there things are slow in any case, or quick API prototyping due implicit &lt;code&gt;return this&lt;/code&gt; nature of the hack: you decide :-)  &lt;h3&gt;Last Improvement&lt;/h3&gt;If you would like to adopt the technique but you want to be able to bring other local variables in that mustached block, you can use this version of the same function: &lt;pre class="code"&gt;&lt;br /&gt;// The Strictly Monocle With Statement&lt;br /&gt;function With(o,a) {&lt;br /&gt;  return function(f) {&lt;br /&gt;    return Function(&lt;br /&gt;      "with(this){return(" + ("" + f).replace(&lt;br /&gt;        "{", "{'use strict';"&lt;br /&gt;      ) + ").apply(this,arguments)}"&lt;br /&gt;    ).apply(o,a);&lt;br /&gt;  };&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;With latest piece of code we can bring in that function whatever we need in this way: &lt;pre class="code"&gt;&lt;br /&gt;With(&lt;br /&gt;  document.body, // the implicit context&lt;br /&gt;  [ // arguments to pass&lt;br /&gt;    jQuery,  // jQuery&lt;br /&gt;    window._ // lo-dash&lt;br /&gt;  ]&lt;br /&gt;)(function($, _){&lt;br /&gt;  // le the magic happens&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;// or simply&lt;br /&gt;With({},[1, 2])(function(a, b){&lt;br /&gt;  alert([a, b]); // 1,2&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;:) Thanks for reading!</content><link rel="replies" type="application/atom+xml" href="http://webreflection.blogspot.com/feeds/891461924419918743/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=34454975&amp;postID=891461924419918743" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/891461924419918743" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/34454975/posts/default/891461924419918743" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WebReflection/~3/RSbhoyHs5ss/resurrecting-with-statement.html" title="Resurrecting The With Statement" /><author><name>Andrea Giammarchi</name><uri>http://www.blogger.com/profile/16277820774810688474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://www.3site.eu/graphic/blogspot_profile.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://webreflection.blogspot.com/2013/01/resurrecting-with-statement.html</feedburner:origLink></entry></feed>
