IIssNan's Notes

Quick notes


  • 首页

  • 归档

  • 标签

  • 搜索

The refactoring tales

发表于 2014-07-26 | | 阅读次数

Welcome to The Refactoring Tales, a book that documents some of the refactorings and changes I’ve made in recent (and mostly real-life) projects. This book isn’t going to teach you about language constructs, conditionals, functions, or so on, but hopefully offer insight into how to take steps to make your code more readable and more importantly, maintainable.

Jack Franklin

Examples of using apply function

发表于 2014-07-25 | | 阅读次数

Example 1: Append an array to another array.

1
2
3
4
5
var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];
Array.prototype.push.apply(arr1, arr2);
console.log(arr1); // [1, 2, 3, 4, 5, 6]

Example 2: Get the max/min item in an array of numbers.

1
2
3
var numbers = [12, 1, 35, 98, 34, 100];
var max = Math.max.apply(Math, numbers);
var min = Math.min.apply(Math, numbers);

Grunt import external data

发表于 2014-07-24 | | 阅读次数

Grunt has two methods for importing external data:

  • grunt.file.readJSON
  • grunt.file.readYAML

For example, you can load data from a file into configuration of GruntFile:

1
2
3
4
5
6
7
8
9
10
11
12
module.exports = function (grunt) {
grunt.config.init({
colors: grunt.file.readJSON('colors.json'),
white: '<%= colors.white %>',
green; '<%= colors.green %>'
});
grunt.registerTask('default', function () {
grunt.log.writeln(grunt.config.get('green'));
});
});

Using Tempalte to store external data into specific config properties, such as white and green in the above example. Then, you can get the data by method grunt.config.get().

Git pull with rebase and why

发表于 2014-07-23 | | 阅读次数

Users of Git are hopefully aware that a git pull does a git fetch to pull down data from the specified remote, and then calls git merge to join the changes received with your current branch’s work. However, that may not always be the best case. You can also rebase the changes in, and that may end up being a lot cleaner. This can be done simply by tacking on the --rebase option when you pull, like so:

1
git pull --rebase <remote name> <branch name>

Read More on Git Ready

Related Question:

  • Difference between git pull and git pull –rebase

List available grunt tasks of a project

发表于 2014-07-15 | | 阅读次数

In the project’s directory, run:

1
grunt --help
1…151617…37
IIssNan

IIssNan

胡编一通,乱写一气

183 日志
6 分类
111 标签
RSS
GitHub Twitter 豆瓣 知乎
© 2011 - 2017 IIssNan
由 Hexo 强力驱动
主题 - NexT.Pisces
0%