for (var key in validation_messages) {
// skip loop if the property is from prototype
if (!validation_messages.hasOwnProperty(key)) continue;
var obj = validation_messages[key];
for (var prop in obj) {
// skip loop if the property is from prototype
if(!obj.hasOwnProperty(prop)) continue;
// your code
alert(prop + " = " + obj[prop]);
}
}
Number.isInteger(nTest);
It is a unary operator that takes the expression to its right performs this small algorithm on it (where n
is the expression to the right of the tilde): -(n+1)
console.log(~-2); // 1
console.log(~-1); // 0
console.log(~0); // -1
console.log(~1); // -2
~~
converts a string to number
console.log(~~-2); // -2
console.log(~~"-1"); // -1
If you look back at the first code sample, you’ll see that using ~ on -1 converts it to 0. The number 0 is a falsey value, meaning that it will evaluate to false when converted to a Boolean. That might not seem like a big insight at first, but remember functions like indexOf will return -1 when the query is not found. This means that instead of writing something similar to this:
if (someStr.indexOf("a") >= 0) {
// Found it
} else {
// Not Found
}
You can now have fewer characters in your code so you can write it like this:
if (~someStr.indexOf("a")) {
// Found it
} else {
// Not Found
}
function sortProperties(sortObj, fn) {
// convert object into array
var sortable = [];
for (var key in sortObj) {
// skip loop if the property is from prototype
if (!sortObj.hasOwnProperty(key)) {
continue;
}
var obj = sortObj[key];
sortable.push([obj.overlap, obj.overlapWith]); // each item is an array in format [key, value]
}
// sort items by value
if (fn) {
sortable.sort(fn);
}
return sortable; // array in format [ [ key1, val1 ], [ key2, val2 ], ... ]
}
- typeof
- instanceof
- obj.constructor
- func.prototype, proto.isPrototypeOf
A few examples:
function Foo() {}
var foo = new Foo();
typeof Foo; // == "function"
typeof foo; // == "object"
foo instanceof Foo; // == true
foo.constructor.name; // == "Foo"
Foo.name // == "Foo"
Foo.prototype.isPrototypeOf(foo); // == true
Foo.prototype.bar = function (x) {return x+x;};
foo.bar(21); // == 42
echo "# snippes" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/S3lected/snippes.git
git push -u origin master
git remote add origin https://github.com/S3lected/snippes.git
git push -u origin master
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore:
First commit any outstanding code changes, and then, run this command: git rm -r --cached .
This removes any changed files from the index(staging area), then just run: git add .
Commit it: git commit -m ".gitignore is now working"
npm update
add in ~/.npmrc
follow line https-proxy=http://urlToProxy:8080
> diskutil list
> diskutil unmountDisk /dev/disk2
> sudo dd if=/path/to/foo/bar/image.iso of=/dev/disk2 bs=1m
> diskutil eject /dev/disk2