Skip to content

Instantly share code, notes, and snippets.

@ksdev-pl
ksdev-pl / this.md
Last active August 29, 2015 14:12
"This" in JavaScript #js
  1. The keyword "this" refers to whatever is left of the dot at call-time.
  2. If there's nothing to the left of the dot, then "this" is the root scope (e.g. Window).
  3. A few functions change the behavior of "this"—bind, call and apply
  4. The keyword "new" binds this to the object just created

So if you're using the value of "this" in someFunction...

thing.someFunction(); // this === thing
someFunction();       // this === Window
new someFunction(); // this === the newly created object
@ksdev-pl
ksdev-pl / write_append.md
Last active August 29, 2015 14:14
Write / append some text to a file #serwer

If you want to write some text to a file that needs a root privileges, you do it this way:

echo "Text I want to write" | sudo tee /path/to/file > /dev/null

or:

sudo sh -c 'echo "Text I want to write" > /path/to/file'

If you just want to append some text, you do it this way:

@ksdev-pl
ksdev-pl / naturalOrderBy.js
Last active December 2, 2022 11:03
Natural sort orderBy filter for vue.js #js
naturalSort.insensitive = true;
Vue.filter('naturalOrderBy', function (arr, sortKey, reverse) {
if (!sortKey) {
return arr;
}
var order = (reverse && reverse < 0) ? -1 : 1;
return arr.slice().sort(naturalSort.bind(null, sortKey, order));
});