This repository has been archived by the owner on Jan 15, 2019. It is now read-only.
/
1008904.json
1 lines (1 loc) · 15.9 KB
/
1008904.json
1
{"forks":[],"files":{"annotated.js":{"content":"function(p,s,i){ // parent, static, instance in that order\n s = Object.create( p||{}, s); // create the new classes static object\n return( \n s.prototype = Object.create( // create the new instance object\n p&& p.prototype ||{}, i // attach that to the statics prototype method\n )\n ).constructor = s // make the static the instances constructor\n}","size":449,"raw_url":"https://gist.github.com/raw/1008904/b384e4b704db0270603b8714496acf5cb457a593/annotated.js","filename":"annotated.js"},"LICENSE.txt":{"content":" DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE\n Version 2, December 2004\n\n Copyright (C) 2011 Kambfhase\n\n Everyone is permitted to copy and distribute verbatim or modified\n copies of this license document, and changing it is allowed as long\n as the name is changed.\n\n DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE\n TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n 0. You just DO WHAT THE FUCK YOU WANT TO.","size":462,"raw_url":"https://gist.github.com/raw/1008904/35f08789500ff639e7223c43504c8ea64bed1cce/LICENSE.txt","filename":"LICENSE.txt"},"README.md":{"content":"class inheritance the way it should have been in JavaScript.\n\nA small sketchup of how the resulting object structure will look up: http://www.abload.de/image.php?img=inhnc45.png\n\nUsage:\n\n f(p,s,i) // returns the newly created class\n p: // the parent class\n s: // a property descriptor map for the static members\n i: // a property descriptor map for the instance members\n\n all of p,s,i are optional.\n\n to create a new instance of the newly created klass do:\n klass=f(p,s,i)\n Object.create(klass.prototype) // new instance\n\n to check if an object is an instance of klass do\n klass.isPrototypeOf( obj)\n\n for more examples see the unit tests.","size":682,"raw_url":"https://gist.github.com/raw/1008904/35878f66076f3bc2fa7e349c0c2d2a671aba9699/README.md","filename":"README.md"},"index.js":{"content":"function(p,s,i){s=Object.create(p||{},s);return(s.prototype=Object.create(p&&p.prototype||{},i)).constructor=s}","size":111,"raw_url":"https://gist.github.com/raw/1008904/f5d7001068a98f5720b86f5314a71cc66c7fecf2/index.js","filename":"index.js"},"test.html":{"content":"<!doctype html>\n<html>\n<head>\n<link href=\"qunit.css\" rel=\"Stylesheet\" type=\"text/css\"/>\n<title>Unit Tests</title>\n</head>\n<body>\n\n <h1 id=\"qunit-header\">Din - Unit Tests</h1>\n <h2 id=\"qunit-banner\"></h2>\n <div id=\"qunit-testrunner-toolbar\"></div>\n <h2 id=\"qunit-userAgent\"></h2>\n <ol id=\"qunit-tests\"></ol>\n <div id=\"qunit-fixture\">test markup, will be hidden</div>\n \n<script src=\"qunit.js\"></script>\n<script>\nvar Class={\n create2: \n \n\nfunction f(p,s,i){s=Object.create(p||{},s);return (s.prototype=Object.create((p&&p.prototype)||{},i)).constructor=s}\n,\ncreate: function(o){\n var k = this.create2(o.parent,o.static,o.instance);\n \n if( !k.create)\n k.create = function(){return Object.create(this.prototype)};\n \n if( !k.is)\n k.is = function( obj){ return this.prototype.isPrototypeOf(obj);};\n \n return k;\n}\n\n}\n\n</script>\n<script>\n\nmodule(\"Basic basics\");\n\ntest(\"Basic setup\", function(){\n expect(3);\n ok( Class,\"Class exists\");\n ok( Class.create,\"Class.create exists\");\n equals( typeof Class.create, \"function\", \"Class.create is a function\"); \n});\n\nmodule(\"simple class\");\n\nvar Klass = Class.create({\n // no parent\n \"static\":{\n method: {\n value: function(){\n return 2;\n }\n },\n self: {\n value: function(){\n return this;\n }\n }\n },\n instance: {\n method: {\n value: function(){\n return 2;\n }\n },\n prop: {\n value: \"foo\",\n enumerable: true,\n writable:true,\n configurable:true\n },\n accessor: {\n get: function(){\n return 1;\n },\n enumerable: true\n },\n self: {\n value: function(){\n return this;\n }\n }\n }\n}),k=Klass.create();\n\ntest(\"simple basics\", function(){\n expect(7);\n \n ok( Klass,\"Klass exists\");\n ok( Klass.prototype,\"Klass.prototype exists\");\n ok( Klass.prototype.constructor== Klass, \"Klass is its instances Constructor\");\n equals( typeof Klass.create, \"function\", \"Klass.create is a function\"); \n equals( typeof Klass.is, \"function\", \"Klass.is is a function\");\n \n ok( Klass.create(), \"Klass.create returns something\");\n\n //ok( k instanceof Klass, \"k is an instance of Klass\"); //?\n ok( Klass.is( k),\"k is an instance of Klass\");\n});\n\ntest(\"correct instances\",function(){\n expect(7);\n \n equals( typeof k.method, \"function\",\"k.method should be a function\");\n equals( k.method(), 2, \"yay!\");\n equals( typeof k.prop, \"string\",\"k.prop is a string\");\n equals( k.prop, \"foo\");\n equals( typeof k.accessor, \"number\",\"getter returns a value\");\n equals( k.accessor, 1,\"accessor returns gettet value\");\n ok( k.self() == k,\"correct <this>\");\n});\n\ntest(\"correct descriptors\",function(){\n var p = Klass.prototype, d;\n expect(13);\n \n ok( p.hasOwnProperty(\"method\"),\"method should be on the prototype\");\n d=Object.getOwnPropertyDescriptor(p, \"method\");\n equals(d.enumerable, false, \"method is not enumerable\");\n equals(d.writable, false, \"method is not writable\");\n equals(d.configurable, false, \"method is not configurable\");\n \n ok( p.hasOwnProperty(\"prop\"),\"prop should be on the prototype\");\n d=Object.getOwnPropertyDescriptor(p, \"prop\");\n equals(d.value, \"foo\", \"prop is 'foo'\");\n equals(d.enumerable, true, \"prop is enumerable\");\n equals(d.writable, true, \"prop is writable\");\n equals(d.configurable, true, \"prop is configurable\");\n \n ok( p.hasOwnProperty(\"accessor\"),\"accessor should be on the prototype\");\n d=Object.getOwnPropertyDescriptor(p, \"accessor\");\n ok(d.get, \"getter is defined\");\n equals(d.enumerable, true, \"accessor is enumerable\");\n equals(d.configurable, false, \"accessor is not configurable\");\n});\n\ntest(\"Staticness\",function(){\n expect(4);\n\n ok( Klass.method, \"static method exists\");\n ok( Klass.method != k.method, \"static and instance method differ\");\n equals( Klass.method(), 2, \"static returns correct result\");\n ok( Klass.self() == Klass, \"correct <this>\");\n});\n\nmodule(\"inheritance\");\n\nvar A = Class.create({\n instance : {\n foo: {\n value: function(){\n return \"A foo\";\n }\n }\n }\n}),\nB = Class.create({\n parent: A,\n \"static\":{\n bar: {\n value: function(){\n return \"b bar\";\n }\n }\n }\n}),\nC = Class.create({\n parent: B,\n instance: {\n foo: {\n value: function(){\n return \"C \"+A.prototype.foo.call(this);\n }\n }\n }\n}),a=A.create(),b=B.create(),c=C.create();\n\ntest(\"static inheritance\", function(){\n expect(4);\n\n ok( !!B.bar(),\"B has a static bar method\");\n ok( !!C.bar(),\"C has a static bar method\");\n equals( B.bar, C.bar,\"C inherits static method from B!\");\n equals( B.bar(), C.bar(), \"same!\");\n});\n\n\ntest(\"creation\", function(){\n expect(9);\n\n equals( A.is( a), true, \"a is an instance of A\");\n equals( A.is( b), true, \"b is an instance of A\");\n equals( A.is( c), true, \"c is an instance of A\");\n equals( B.is( a), false, \"a is not an instance of B\");\n equals( B.is( b), true, \"b is an instance of B\");\n equals( B.is( c), true, \"c is an instance of B\");\n equals( C.is( a), false, \"a is not an instance of C\");\n equals( C.is( b), false, \"b is not an instance of C\");\n equals( C.is( c), true, \"c is an instance of C\");\n});\n\ntest(\"instance inheritance\",function(){\n expect(4);\n \n equals( a.foo(), \"A foo\", \"a foo is a foo :|\");\n equals( b.foo(), \"A foo\", \"b.foo is also a foo :|\");\n equals( b.foo, a.foo, \"same foo methods\");\n equals( c.foo(), \"C A foo\",\"c foo is c a foo\");\n});\n\n</script>\n</body>\n</html>","size":5877,"raw_url":"https://gist.github.com/raw/1008904/aa09bf67ca066658680c708554407397a7041506/test.html","filename":"test.html"},"package.json":{"content":"{\n \"name\": \"class inheritance\",\n\n \"description\": \"class inheritance the way it should have been in JavaScript.\",\n\n \"keywords\": [\n \"classes\",\n \"inheritance\"\n ]\n}","size":170,"raw_url":"https://gist.github.com/raw/1008904/8917c2ec157c93d7bd3878a77b20fe4692308573/package.json","filename":"package.json"}},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"git_pull_url":"git://gist.github.com/1008904.git","url":"https://api.github.com/gists/1008904","description":"class inheritance for real","public":true,"html_url":"https://gist.github.com/1008904","comments":2,"git_push_url":"git@gist.github.com:1008904.git","history":[{"committed_at":"2011-08-15T09:31:41Z","change_status":{"deletions":1,"additions":1,"total":2},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/697ac26d43dccada5c47c807ac6a69b8296c889f","version":"697ac26d43dccada5c47c807ac6a69b8296c889f"},{"committed_at":"2011-07-27T16:21:12Z","change_status":{"deletions":1,"additions":1,"total":2},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/2dbcad5f7d4aa3ee49faf0ac30e5144524865c62","version":"2dbcad5f7d4aa3ee49faf0ac30e5144524865c62"},{"committed_at":"2011-07-27T15:50:51Z","change_status":{"deletions":1,"additions":1,"total":2},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/f73e5ba7865fb9b876675bb4b7d69d21ab40b2d1","version":"f73e5ba7865fb9b876675bb4b7d69d21ab40b2d1"},{"committed_at":"2011-07-27T13:22:54Z","change_status":{"deletions":2,"additions":2,"total":4},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/75e3dad74a20310792b8d7a1b2f7f17c35a7f923","version":"75e3dad74a20310792b8d7a1b2f7f17c35a7f923"},{"committed_at":"2011-07-27T13:05:38Z","change_status":{"deletions":2,"additions":2,"total":4},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/b6fb0ad77cad59ef45ab097b24a635de34cbbb23","version":"b6fb0ad77cad59ef45ab097b24a635de34cbbb23"},{"committed_at":"2011-07-27T12:49:43Z","change_status":{"deletions":2,"additions":2,"total":4},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/bb866665be8080b3a65de097bcd885cf3c784f3c","version":"bb866665be8080b3a65de097bcd885cf3c784f3c"},{"committed_at":"2011-07-27T11:43:37Z","change_status":{"deletions":0,"additions":0,"total":0},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/4f5da5aae6d5da726268633120daf4e6d37c2261","version":"4f5da5aae6d5da726268633120daf4e6d37c2261"},{"committed_at":"2011-07-26T21:16:18Z","change_status":{"deletions":7,"additions":4,"total":11},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/e36e3de75d903fae3c85a4c99b8e79c6ec9ab7f8","version":"e36e3de75d903fae3c85a4c99b8e79c6ec9ab7f8"},{"committed_at":"2011-06-11T13:30:16Z","change_status":{"deletions":4,"additions":4,"total":8},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/e5840740d141a0003a3aa613eeba8414434dd9ad","version":"e5840740d141a0003a3aa613eeba8414434dd9ad"},{"committed_at":"2011-06-06T11:12:19Z","change_status":{"deletions":6,"additions":8,"total":14},"user":{"url":"https://api.github.com/users/Kambfhase","avatar_url":"https://secure.gravatar.com/avatar/a695053c20d82044680643fc355f4d81?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Kambfhase","id":295387},"url":"https://api.github.com/gists/1008904/986e0f1f6744c01ccdecb3906be81ce3ccf7d9cf","version":"986e0f1f6744c01ccdecb3906be81ce3ccf7d9cf"}],"fork_of":{"files":{"annotated.js":{"size":396,"raw_url":"https://gist.github.com/raw/962807/cd5c9947f41abdfd608a8995e02ba4a160bb2a08/annotated.js","filename":"annotated.js"},"LICENSE.txt":{"size":483,"raw_url":"https://gist.github.com/raw/962807/dfb480a5038214d152544bddb412dfe2e8656413/LICENSE.txt","filename":"LICENSE.txt"},"README.md":{"size":1457,"raw_url":"https://gist.github.com/raw/962807/6832f0d91100cdb4373f2cfd42e12fc06532eac9/README.md","filename":"README.md"},"index.js":{"size":140,"raw_url":"https://gist.github.com/raw/962807/c89ef021071af3b78eea79bcf0288a6e7873a62e/index.js","filename":"index.js"},"test.html":{"size":393,"raw_url":"https://gist.github.com/raw/962807/22ac2a8244f3a1fd650faf81dfdde9cbae7453e5/test.html","filename":"test.html"},"package.json":{"size":241,"raw_url":"https://gist.github.com/raw/962807/323b4aaa685a2bf7b15abdeed2fe03e11d63859f/package.json","filename":"package.json"}},"user":{"url":"https://api.github.com/users/140bytes","avatar_url":"https://secure.gravatar.com/avatar/53e21508b6995fa42f2e034b87daa901?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"140bytes","id":777161},"git_pull_url":"git://gist.github.com/962807.git","url":"https://api.github.com/gists/962807","description":"140byt.es -- Click ↑↑ fork ↑↑ to play!","public":true,"html_url":"https://gist.github.com/962807","comments":45,"git_push_url":"git@gist.github.com:962807.git","id":"962807","updated_at":"2011-05-18T12:15:41Z","created_at":"2011-05-09T16:13:35Z"},"id":"1008904","updated_at":"2011-07-27T16:21:12Z","created_at":"2011-06-05T11:59:37Z"}