Wpis z mikrobloga

#javascript #js #webdev
To samo na pastebinie
1) http://pastebin.com/7an9kSqR
2) http://pastebin.com/YxJELBfP
Protip, jeśli piszecie coś tylko dla #firefox możecie skorzystać z jednej rzeczy, która nie jest częścią JS. Konkretnie chodzi tu o jednoliniową (nie wiem jak to nazwać) funkcję, np.

function funcName() "wykop"; // funcName() zwraca strring wykop

function funcName2() ({

get isThisWindow() this === window,

isThisWindow2: () => this === window,

get ["blabla"]() "computed names are supported toooooo"

});

let yep = funcName2();

yep.isThisWindow; // false

yep.isThisWindow2(); // true

yep.blabla(); //"computed names are supported toooooo"


Dlaczego jest to fajne urozmaicenie? Ponieważ this w arrow function jest leksykalne -> niezbyt miło pracuje się z nim na obiektach.
Nieco bardziej rozbudowany przykład wykorzystujący moduł sdk/core/heritage z addon sdk FF.
Wycinek mojego kodu:

const contentModXHR = Class({

implements: [privacyMode, contentMod],

initialize(file, value = true, ...args){

this.file = ${value}file.js;

this.value = value;

this.include = this.makeURIRules("*.wykop.pl");

this.include = this.makeURIRules("http://www.wykop.pl/ramka/");

},

makeURIRules: rules => Array.isArray(rules) ? rules.map(rule => new MatchPattern(rule)) : new MatchPattern(rules),

matchURI(window) (!this.include || (Array.isArray(this.include) ? this.include.filter(rule => rule.test(window.url || window.location.href)).length > 0 : this.include.test(window.url || window.location.href))) && >(!this.exclude || (Array.isArray(this.exclude) ? 0 === this.exclude.filter(rule => rule.test(window.url || window.location.href)).length : !this.exclude.test(window.url || window.location.href))),>

get redState() ({

"16": ./icons/${this.value}_red_16.png,

"32": ./icons/${this.value}_red_32.png,

"36": ./icons/${this.value}_red_36.png,

"64": ./icons/${this.value}_red_64.png

})

});
  • Odpowiedz