Skip to main content

Home/ javascript/ Group items tagged implementation

Rss Feed Group items tagged

Ivan Pavlov

oni - structured concurrency - 0 views

  • Oni is a framework for managing the control flow of concurrent applications. There are two central ideas to Oni: To make concurrent actions composable by implementing 'pseudo-sequential' control structures with which asynchronous actions can be choreographed in the same way in which traditional sequential control structures are used to choreograph conventional synchronous actions. Ok, I'm not sure I even understand that myself. But please read on anyway :-) To leverage the facilities of a "host language" rather than implement a complete programming language from scratch. Oni can be implemented as a set of functions ("Oni operators") in a suitable host language, such as JavaScript or C++ (any reasonable language will do). Our current implementation, dubbed Oni/JS, is in JavaScript, targeted at in-browser use (should work in any modern browser - FF, Chrome, Safari, IE, ...). Oni requires no preprocessing or precompilation; an Oni program is a just an expression in the host language.
  •  
    Oni is a framework for managing the control flow of concurrent applications.
Javier Neira

Perfection kills » Understanding delete - 3 views

  • All because it’s not possible to delete variables in Javascript. At least not when declared in such way.
  • It’s almost as if Firebug follows some other rules of deletion. It is Firebug that has led Stoyan astray! So what is really going on here?
  • we need to understand how delete operator works in Javascript: what exactly can and cannot be deleted and why.
  • ...35 more annotations...
  • var o = { x: 1 }; delete o.x; // true o.x; // undefined
  • var x = 1; delete x; // false x; // 1
  • function x(){} delete x; // false typeof x; // "function"
  • Note that delete only returns false when a property can not be deleted.
  • variable instantiation and property attributes
  • Global code, Function code and Eval code.
  • When a source text is treated as a Program, it is executed in a global scope, and is considered a Global code.
  • Anything that’s executed directly within a function is, quite obviously, considered a Function code. In browsers, content of event attributes (e.g. <p onclick="...">) is usually parsed and treated as a Function code.
  • text that’s supplied to a built-in eval function is parsed as Eval code. We will soon see why this type is special.
  • And now that we know the difference between property assignment and variable declaration — latter one sets DontDelete, whereas former one doesn’t — it should be clear why undeclared assignment creates a deletable property:
  • As you can see, execution contexts can logically form a stack. First there might be Global code with its own execution context; that code might call a function, with its own execution context; that function could call another function, and so on and so forth. Even if function is calling itself recursively, a new execition context is being entered with every invocation.
  • Every execution context has a so-called Variable Object associated with it. Similarly to execution context, Variable object is an abstract entity, a mechanism to describe variable instantiation. Now, the interesing part is that variables and functions declared in a source text are actually added as properties of this Variable object.
  • When control enters execution context for Global code, a Global object is used as a Variable object. This is precisely why variables or functions declared globally become properties of a Global object:
  • The behavior is actually very similar: they become properties of Variable object. The only difference is that when in Function code, a Variable object is not a Global object, but a so-called Activation object. Activation object is created every time execution context for Function code is entered.
  • and a special Arguments object (under arguments name). Note that Activation object is an internal mechanism and is never really accessible by program code.
  • within Eval code are created as properties of calling context’s Variable object. Eval code simply uses Variable object of the execution context that it’s being called within:
  • Execution context When ECMAScript code executes, it always happens within certain execution context.
  • When declared variables and functions become properties of a Variable object — either Activation object (for Function code), or Global object (for Global code), these properties are created with DontDelete attribute. However, any explicit (or implicit) property assignment creates property without DontDelete attribute. And this is essentialy why we can delete some properties, but not others:
  • Special arguments variable (or, as we know now, a property of Activation object) has DontDelete. length property of any function instance has DontDelete as well:
  • As you might remember, undeclared assignment creates a property on a global object.
  • Now that it’s clear what happens with variables (they become properties), the only remaining concept to understand is property attributes. Every property can have zero or more attributes from the following set — ReadOnly, DontEnum, DontDelete and Internal. These attributes serve as sort of flags — an attribute can either exist on a property or not. For the purposes of today’s discussion, we are only interested in DontDelete.
  • Variables declared within Eval code are actually created as properties without DontDelete:
  • This interesting eval behavior, coupled with another aspect of ECMAScript can technically allow us to delete non-deletable properties. The thing about function declarations is that they can overwrite same-named variables in the same execution context:
  • Note how function declaration takes precedence and overwrites same-named variable (or, in other words, same property of Variable object). This is because function declarations are instantiated after variable declarations, and are allowed to overwrite them
  • If we declare function via eval, that function should also replace that property’s attributes with its own. And since variables declared from within eval create properties without DontDelete, instantiating this new function should essentially remove existing DontDelete attribute from the property in question, making that property deletable (and of course changing its value to reference newly created function).
  • Unfortunately, this kind of spoofing doesn’t work in any implementation I tried. I might be missing something here, or this behavior might simply be too obscure for implementors to pay attention to
  • this.x = 1; delete x; // TypeError: Object doesn't support this action
  • var x = 1; delete this.x; // TypeError: Cannot delete 'this.x'
  • It’s as if variable declarations in Global code do not create properties on Global object in IE.
  • Not only is there an error, but created property appears to have DontDelete set on it, which of course it shouldn’t have:
  • “The global variable object is implemented as a JScript object, and the global object is implemented by the host.
  • Note how this and window seem to reference same object (if we can believe === operator), but Variable object (the one on which function is declared) is different from whatever this references.
  • delete doesn’t differentiate between variables and properties (in fact, for delete, those are all References) and really only cares about DontDelete attribute (and property existence).
  • The moral of the story is to never trust host objects.
  • Few restrictions are being introduced. SyntaxError is now thrown when expression in delete operator is a direct reference to a variable, function argument or function identifier. In addition, if property has internal [[Configurable]] == false, a TypeError is thrown:
Javier Neira

Three map implementations in javascript. Which one is better? - Stack Overflow - 1 views

  • if (!Array.prototype.map) {  Array.prototype.map = function(fun /*, thisp*/)   {    var len = this.length >>> 0;  // make sure length is a positive number    if (typeof fun != "function") // make sure the first argument is a function      throw new TypeError();    var res = new Array(len);  // initialize the resulting array    var thisp = arguments[1];  // an optional 'context' argument    for (var i = 0; i < len; i++) {      if (i in this)        res[i] = fun.call(thisp, this[i], i, this);  // fill the resulting array    }    return res;  };}
  •  
    if (!Array.prototype.map) { Array.prototype.map = function(fun /*, thisp*/) { var len = this.length >>> 0; // make sure length is a positive number if (typeof fun != "function") // make sure the first argument is a function throw new TypeError(); var res = new Array(len); // initialize the resulting array var thisp = arguments[1]; // an optional 'context' argument for (var i = 0; i < len; i++) { if (i in this) res[i] = fun.call(thisp, this[i], i, this); // fill the resulting array } return res; }; }
Ivan Pavlov

ArcLite - Arc Ported to JavaScript - 0 views

  •  
    Jonathan Tang has fallen into the Arc fun and took some time to fully implement it in JavaScript.
yc c

RDFa Bookmarklets - 0 views

  •  
    This is the home of the RDFa Javascript implementation, including the RDFa bookmarklets.
Ivan Pavlov

narwhal - 0 views

shared by Ivan Pavlov on 02 Jun 09 - Cached
  •  
    Narwhal is a server-side JavaScript standard library conforming to the ServerJS standard. It is designed to work with multiple JavaScript interpreters, and to be easy to add support for new interpreters. Wherever possible, it is implemented in pure JavaScript to maximize reuse of code between platforms.
yc c

Sizzle JavaScript Selector Library - 1 views

shared by yc c on 30 Jan 10 - Cached
  •  
    A pure-JavaScript CSS selector engine designed to be easily dropped in to a host library. Sizzle supports virtually all CSS 3 Selectors - this even includes some parts that are infrequently implemented such as escaped selectors (".foo\\+bar"), Unicode selectors, and results returned in document order. There are a few notable exceptions to the CSS 3 selector support (the reasoning for this decision can be found here): * :root * :target * :nth-last-child * :nth-of-type / :nth-last-of-type / :first-of-type / :last-of-type / :only-of-type * :lang() In addition to the CSS 3 Selectors Sizzle supports the following additional selectors or conventions.
yc c

Unverse javascript library - 5 views

  •  
    Unverse is a lightweight - absolutely tiny - collection of terse cross-browser javascript functions that perform common tasks, including a lightbox, ajax calls, animation and drag and drop. It implements DOMready. 
yc c

CSS Gradients via Canvas | Weston Ruter - 2 views

  •  
    CSS Gradients via Canvas provides a subset of WebKit's CSS Gradients proposal for browsers that implement the HTML5 canvas element. To use, just include css-gradients-via-canvas.js (12KB) anywhere on the page
Julian Knight

JQuery Cycle Plugin - 1 views

  •  
    "The jQuery Cycle Plugin is a lightweight slideshow plugin. Its implementation is based on the InnerFade Plugin by Torsten Baldes, the Slideshow Plugin by Matt Oakes, and the jqShuffle Plugin by Benjamin Sterling. It supports pause-on-hover, auto-stop, auto-fit, before/after callbacks, click triggers and many transition effects. It also supports, but does not require, the Metadata Plugin and the Easing Plugin." This is one that really works and is genuinely easy to set up - no complex CSS like so many of these things. It also works very well with just text or other HTML structures.
Joelle Nebbe-Mornod

markItUp! Universal Markup Editor - 0 views

  • markItUp! is a JavaScript plugin built on the jQuery library. It allows you to turn any textarea into a markup editor. Html, Textile, Wiki Syntax, Markdown, BBcode or even your own Markup system can be easily implemented.
Ivan Pavlov

Service Mapping Description Proposal - JSON Schema - 0 views

  •  
    A Service Mapping Description (SMD) is a JSON representation describing web services. An SMD can defines the various aspects of a web service such that clients can coherently interact with the web services. An SMD can be used by generic tools to generate interfaces, human and programmatic, to access available web services. A wide array of web services can be described with SMD including REST services and JSON-RPC services. The SMD format is designed to be flexible, compact, simple, readable, and easily implemented.
Ivan Pavlov

http://www.cs.ucla.edu/~awarth/ometa - 0 views

  • OMeta is a new object-oriented language for pattern matching. It is based on a variant of Parsing Expression Grammars (PEGs) which we have extended to handle arbitrary data types. OMeta's general-purpose pattern matching facilities provide a natural and convenient way for programmers to implement tokenizers, parsers, visitors, and tree transformers, all of which can be extended in interesting ways using familiar object-oriented mechanisms.
Ivan Pavlov

xmlhttprequest - Google Code - 0 views

  •  
    Deliver standard-compliant (W3C) cross-browser implementation of the XMLHttpRequest object
Bartłomiej Małysz

Yetii - Yet (E)Another JavaScript Tab Interface Implementation | kminek.pl - 0 views

  •  
    Very nice menu tabination structure with using of pure lightweight javascript structure and made by Pole! TY Kminek.
Javier Neira

JavaScript EE, Part 1: Run JavaScript files on the server side - 0 views

  • freedom to use the same JavaScript routines on both servers and clients. In addition, the techniques presented throughout this series will allow you to maintain a single code base for both Ajax and non-Ajax clients
  • This double-coding issue can be avoided by using JavaScript combined with Java code on the server side, getting full support of scripting languages through the javax.script API. In addition, the Java SE Development Kit (JDK) 6 already includes Mozilla's Rhino JavaScript engine, which means no setup is required.
  • the toSource() method, which all JavaScript objects must have.
  • ...5 more annotations...
  • engine.eval(scriptReader, vars);
  • sun.org.mozilla.javascript.internal.NativeObject
  • all data exchange between the Java code and the executed script should be done through primitive variables, strings, and Java objects (for example, beans) whose properties and methods can be accessed very easily in the JavaScript code. Simply said, don't try to access native JavaScript objects in your Java code. Use Java objects in the JavaScript code instead.
  • Note that javax.script.Invocable is an optional interface, which some script engines may not implement. The JavaScript engine that comes with JDK 6 does support this interface.
  • you can significantly reduce the execution time by compiling the scripts, using the methods provided by another optional interface named javax.script.Compilable, which is supported by the JavaScript engine of JDK 6.
1 - 20 of 22 Next ›
Showing 20 items per page