## page was renamed from SpiderMonkey = SpiderMonkey = SpiderMonkey is Mozilla's [[Javascript]] engine written in C/C++. It is used in various Mozilla products, including Firefox, and is available under the MPL2. == Example code == {{{#!highlight javascript #!/usr/bin/js function CTest(){ this.counter=0; } CTest.prototype.increment=function(){ this.counter++; }; CTest.prototype.show=function(){ putstr(this.counter); putstr("\r\n"); }; var c = new CTest(); var d = new CTest(); c.increment(); c.increment(); c.increment(); c.show(); d.increment(); d.increment(); d.show(); }}} Run it with: * chmod 755 test.js * ./test.js SpiderMonkey is installed on Slackware 14. == Windows binary == * https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/jsshell-win64.zip == Example of prototype/inheritance == * https://developer.mozilla.org/en/docs/Web/JavaScript/Inheritance_and_the_prototype_chain When it comes to inheritance, Javascript only has one construct: objects. Each object has an internal link to another object called its prototype (__proto__). Javascript objects are dynamic "bags" of properties (referred to as own properties). JavaScript objects have a link to a prototype object. {{{#!highlight javascript // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects var a = {"key":"A value"}; var b = {}; b.__proto__ = a; // set a as prototype of b . b inherits a /*var b = Object.create( a );*/ b.other="aaaa"; if( ! b.hasOwnProperty('key') ) print( "b doesn't have own property key" ); if( b.hasOwnProperty('other') ) print( b.other ); if( a.hasOwnProperty('key') ) print( a['key'] ); if( a.hasOwnProperty('other') ) print( a['other'] ); b.key='Other Value'; // b has own key "key" and a has also key "key" with different value print('\nkeys in object a'); for(var key in a){ print( key ,'->' , a[key] ); } print('\nKeys in object b'); for(var key in b){ print( key ,'->' , b[key] ); } print('Value for key in prototype of b' , b.__proto__.key ); //------- print(); function f(){ this.propx='asdf'; this.fn=function(){print("aaaa");}; this.nr=123.4; } f.prototype.protoFn=function(){ print("bbb"); }; var x = new f(); print('x instance of f ' , x instanceof f); print('x is type of ' + typeof f); print('x instance of object ' , x instanceof Object); print('x instance of Array ' , x instanceof Array); for(var key in x){ print( key ,':' , x[key] , x.hasOwnProperty(key) , typeof x[key] ); } print( JSON.stringify( x ) ); }}}