This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * If you want to set the default value of an attribute to be an array or object, | |
| * doing this fails: | |
| */ | |
| var MyClass = Y.Base.create('myClass', Y.Base, [], {}, { | |
| ATTRS: { | |
| myAttr: { value: [] } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Monster { | |
| // Goes on the instance | |
| own name; | |
| // Goes on the instance and is private | |
| // In the lexical context of a member of the class it can be accessed with {{Instance}}.health or {{Instance}}["health"] | |
| private own health = 10; | |
| constructor(name) { | |
| this.name = name; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.Class = (function () { | |
| function subclass(superclass, proto) { | |
| proto = proto || {}; | |
| var constructor = proto.constructor; | |
| if (!constructor) { | |
| constructor = proto.constructor = function () {}; | |
| } | |
| if (superclass) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Person = Function.create(null, { | |
| constructor: function (name) { | |
| this.name = name; | |
| }, | |
| say: function (message) { | |
| return this.name + ' says: ' + message; | |
| } | |
| }); | |
| var Pirate = Person.extend({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // In this case async3() won't be executed instantly but rather after async1 and async2 are completed | |
| Y.when(async1(), async2()).then(async3()).end(function () { | |
| console.log('success'); | |
| }, function () { | |
| console.log('failure'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ////////// API ////////// | |
| // Code by Axel Rauschmayer | |
| // Based on Selfish https://github.com/Gozala/selfish | |
| // To be part of ECMAScript.next | |
| if (!Object.getOwnPropertyDescriptors) { | |
| Object.getOwnPropertyDescriptors = function (obj) { | |
| var descriptors = {}; | |
| Object.getOwnPropertyNames(obj).forEach(function (prop) { | |
| descriptors[prop] = Object.getOwnPropertyDescriptor(obj, prop); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // example module | |
| YUI.add('foo', function (Y) { | |
| // each of these modules must have a class named exactly like the module | |
| function Foo() {} | |
| // it's useful, in the case of tabs, | |
| // for these classes to have a focus() method. Check below | |
| Foo.prototype.focus = function () {}; | |
| Y.Foo = Foo; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function aplaneitor2(arr){ | |
| return Array.isArray(arr) ? arr.map(aplaneitor2).join('+') : arr; | |
| } | |
| var test = ["hola", ["soy", ["juan", "fernandez"] ], "y", ["no", "tengo", ["dinero"] ] ]; | |
| console.log(aplaneitor2(test)) // -> hola+soy+juan+fernandez+y+no+tengo+dinero |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function aplaneitor2_ES3(arr) { | |
| arr = arr.concat(); //devolver un nuevo array, no modificar el mismo | |
| var i = 0; | |
| while (i < arr.length) { | |
| if (Object.prototype.toString.call(arr[i]) == '[object Array]') { | |
| Array.prototype.splice.apply(arr, [i, 1].concat(arr[i])); | |
| } else { | |
| i++; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // WEB WORKERS | |
| var worker = new Worker('task.js'); | |
| worker.onmessage = function (e) { | |
| }; | |
| // where's addEventListener? A Worker shoud be an EventEmitter | |
| worker.addEventListener('message', function (e) { | |
| }); | |
| // And you know, on() as an alias of addEventListener makes a lot of sense too |