十八般武艺

学习思考成长


  • 首页

  • 分类

  • 归档

  • 标签

如何判断javascritp变量的类型?

发表于 2016-06-16   |  

在javascript变量的类型可以是以下这些:

  • 函数
  • 对象
  • 数组
  • 字符串
  • 数字
  • null

那么如何判断一个变量是什么类型呢?
我们可以用typeof来得到变量的类型,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//函数
var myFunction = function(){
console.log('hello');
};
//对象
var myObject = {
foo:'bar'
};
// 数组
var myArray = ['a','b','c'];
// 字符串
var myString = 'hello';
// 数字
var myNumber = 3;
console.log(typeof myFunction); // 输出function
console.log(typeof myObject); // 输出object
console.log(typeof myArray); // 输出object --careful!
console.log(typeof myString); // 输出string
console.log(typeof myNumber); // 输出number
console.log(typeof null); // 输出object--carefull!

注意到数组和null被判断成对象类型。

那么怎么判断一个被typeof判断对象的变量的类型,到底是对象,数组,还是null?

1.判断数组,可以用Array.isArray(arr)
2.判断null,可以用Var === null

可以判断变量的类型的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function whatType(v)
{
if(typeof(v) == 'object')
{
if(Array.isArray(arr)){
return 'array';
}
if(v === null)
{
return 'null';
}
return 'object';
}
}
arr = [];
obj = {};
n= null;
console.log(whatType(arr)); // array

Javascript函数

发表于 2016-06-12   |  
  • Javascript函数
    • 什么是JavaScript函数?
    • 如何创建函数?
    • 如何使用函数?
    • 自执行匿名函数
    • 函数作为函数的参数
      • 传递匿名函数作为参数
      • 传递非匿名函数作为参数

Javascript函数

什么是JavaScript函数?

在所有编程语言里,函数是用来包含需要重复执行的代码块,Javascript也不例外。

Javascript函数可以有0到n个参数。

Javascript函数可以返回一个值或0个值。

如何创建函数?

在JavaScript里,有两种创建函数的方法法。

  1. 函数声明法
1
2
3
function foo() {
/* do something */
}
  1. 函数表达式法
1
2
3
var foo = function() {
/* do something */
}

如何使用函数?

下面是使用不同类型函数的例子

  1. 简单函数
1
2
3
4
5
6
var greet = function(person,greeting)
{
var text = greeting+','+person;
console.log(text);
};
greet('Duran','Hello');
  1. 有返回值得函数
1
2
3
4
5
6
var greet = function(person, greeting)
{
var text = greeting+','+person;
return text;
};
console.log(greet('Duran','Hello'));
  1. 返回函数的函数
1
2
3
4
5
6
7
var greet = function(person,greeting)
{
var text = greeting+''+person;
return function(){console.log(text)};
};
var greeting = greet('Duran','hello');
greeting();

自执行匿名函数

在javascript中,自执行匿名函数一种随处可见的函数,所以理解它是非常重要的。

它首先建立一个函数表达式,然后立刻执行它。

注意:所有在自执行匿名函数中声明的变量在函数外部都是不可访问的。

1
2
3
4
(function(){
var foo = 'Hello world';
})()
console.log(foo); //undefined!

函数作为函数的参数

函数在JavaScript中非常重要,它们被当做一等公民,什么是一等公民?就是它们能被赋值给变量,能作为参数传递给另一个函数。

传递匿名函数作为参数

1
2
3
4
5
var myFn = function(fn) {
var result =fn();
console.log(result);
}
myFn(function(){return 'hello world';});

传递非匿名函数作为参数

1
2
3
4
5
6
7
8
var myFn = function(fn) {
var result = fn();
console.log(result);
}
var myOtherFn = function(){
return 'hello world';
}
myFn(myOtherFn);

javascrip入门大纲

发表于 2016-06-11   |  

chapter 1: Javascript basic

Syntax Basics

  1. statemants
  2. variable naming
  3. whitespace
  • Case sensitivity

  • Whitespace

  • Semicolon
    Automatic Semicolon Insertion

Javascript Statements

  1. Values
    • fixed values
    • variable values
  1. Operstors
    *
  2. Expressions
  3. Keywords
  4. Comments

Javascript expressions

Javascript keywords

Comments

Identifiers

极简理财—指数基金定投

发表于 2016-06-10   |  

资产配置

  1. 沪深300 25%
  2. 中证500 25%
  3. 美国标普 25%
  4. 短期债券基金 25%

2015年
债:6.13%
300:1.7%
500: 41.45%
标普:6.73

投资收益:14%

2014年 投资收益 28.7%

2013年 投资收益 7.24%

每年末跌的特别多,第二年提高投资比例

资产配置的关键:不相关性

将投资组合分布于几种不相关的资产,这样可以提高收益同时降低风险。

基本投资组合(不相关)

国内大型公司股票+国内小型公司股票+国外大型公司股票+纯债

500ETF 510500

300ETF 510300

国债ETF 511010

标普500 513500

纳指ETF 513100

每年动态平衡

比如上面把资金做5等分分别买上面的基金,年末调整保持这个比例,用涨的多去填补涨的不那么厉害的。

蛋卷基金原理

股票基金为例,在市场呈现明显的风格轮动趋势时,大盘蓝筹基金和中小成长风格基金便会呈现负相关性。
但是,当市场处于普涨或者熊市极端,他们就会从负相关性变为正相关;多数情况下,债券基金表现会独立于股票型基金

蛋卷20日做一次动态平衡

问题

定投

  1. 避开每月1-8号
  2. 定投2到3只基金,按每月天数平均分开投
  3. 制定好组合,一次性或定投都按比例买,年末调整

费用

场内 <ETF联接 < 场外

止损止盈

每年调整,已经解决这个问题

用钱时,如何卖出

保持持有比例卖出。

如何设置比例和看相关性

风险测试第一步

  1. 客观风险承受能力
  2. 主观风险承受态度

根据建议调整比例第二步

实践起来第三步

  1. 预留3~6个月生活费
  2. 按照比例,分配资产
  3. 按照比例,每月定投
  4. 年终投入,动态平衡

部分极简

有证券账户怎么买

国内股票指数
500ETF 510500
300ETF 510300

中国债券
国债ETF 511010
华夏亚债 001021

外国股票指数
标普500 513500
纳指ETF 513100

固定收益类
P2P
万能险

部分资金做极简

投资组合管理有两种:

  1. 主动管理

主题基金:央企改革,一路一带…

  1. 被动管理

极简投资

收益

从基金成立日开始定投,收益在年化12%

投资的第一目标

  1. 尽量保证本金
  2. 确定的收益率

保本就要确定波动率

收益就要确定目标收益率

用最小的波动率获得最大的目标收益率

资产配置可以在不损失目标收益率的情况下有效减低波动率。

所以要做资产配置

不同资产之间的相关性越低,配置组合的波动也就越低。

目标配置比率

通过调整不同资产的配置比率,会得到一个目标收益率和潜在波动率性价比最高的结果。

如何确定配置比率

IBM Agile for Dummies

发表于 2016-05-26   |  

[TOC]

Chapter 1 Getting the ABCs of Agile

Looking Back at Software Development Approaches

Code-and-Fix/Big Bang development

wrote some code and then fixed incorrect things

software was deliverd all at once, in a “big bang”

Waterfall

  1. Requirement
  2. Design
  3. Development
  4. Integration
  5. Testing
  6. Deployment

Waterfall presented a step forward from Code-and-Fix.

Problems:

  1. Schedule risk
  2. limited flexibility
  3. Reduced customer involvement

The Spiral model

口语和写作

发表于 2016-05-21   |  

把英语用起来

能用英文讲就不用中文讲

Input v.s. Output

可理解性输入决定输出的质量

你要写的好就要读的多

口语用起来1:口语

  • 战胜performance anxiety
    焦虑只会持续几分钟。
    系统脱敏

  • 透析口语圈

    • 对方听不明白也要坚持说,直到说到听明白为止。
    • 逐步扩大口语圈半径,拉拢不熟的人。
      中文回答也没关系,当半个朋友圈
    • 网络口语圈QQ,WeChat
  • 没有练习,直接真刀真枪的用。

口语用起来2:语音

  • VOA慢速英语跟读 - 跟读训练
    不看文本,不是为了听懂,而是尽量模仿语音语调
    小批量,多批次

口语用起来3:流利

正向单词&逆向单词
英语思维是个结果,而不是过程,过程还是翻译
口语流利就是词汇的问题 - 逆向透析

  • 硬件加速PK软件加速
    e.g 西门庆 “当铺”

逆透析:反查中文原著

判断哪些是无法逆向的,然后查词,查一个,漏一个。

一词多意,选择最好记的一个。

逆透析:开会同声传译

逆透析词汇

逆透析:查遍交通环境

五金店
石灰
插座
白水泥
油漆

逆透析:查遍家居环境

衣服架
排气扇
热水器
地拖吧
旅游鞋
卫生纸
垃圾铲
垫子
地砖

英文贴纸在家居上

关键在于使用,结合口语圈

逆透析必须结合口语圈

  • QQ群、微信群
    先查查字典才说-逆透析先行
    • 医学 子宫肌瘤
    • 最大扭矩转速
    • 法国长棍
  • 有input才有output

写作用起来:写作圈

  • 发英文聊天
  • 发英文微博
  • 发英文微信朋友圈
  • 单词拼写正确,请学习AP的记者

写作用起来:激励你的读者

  • 保健因素

    • 卫生、安全、没有低级表达错误
    • Word的 “拼写和语法” 检查
  • 激励因素

    • 好吃、好看、高级表达
    • 模板句

Frederick Herzberg’s
Two-factor theory

写作用起来:模板句

  • 来自原著的模板造句
    I have an entirely new slant to my English learning
  • 强扭的瓜才甜!

写作用起来:增加模板

写作用起来:#占领雅虎

模板句用起来,发一个相关评论并用文中一个模板句。

Homework:All in English Lifestyle

  • 结合专题短透析,每日分享一条新闻链接,并用文中模板写一句评论
  • 每天跟读1段voa special
  • 每日至少逆透析3个生活单词
    *

听力和短读

发表于 2016-05-21   |  

听英文歌

就是为了享受,不是为了学习

听Billboard

为了能唱K, 听历年Billboard Year End.

一个月听一年的Billboard Year End.

找歌单Billboard Year End.

看电影

找电影 百度:变形金刚+ed2k或magnet

关键 无字幕

无字幕,可以将理解集中听力上,而不是字幕阅读
从而打开听力通道,培养听力。

不建议听有声书。

书就是用来读,不是用来听。
书面语录音,不自然,比较难懂。

QQ影音可以给字幕打马赛

不看字幕能懂吗?

看画面,就能懂意思

听力听不懂原因

听的少,听假英语。

关键还是听力词汇量太少

Homeword

每天听歌只听美国BILLBOARD HOT 100
每周看1部无字幕英文电影×4周
每天听电台只听韩国KBS English电台
每天看电视只看韩国Arirang电视台
每日专题透析一个英文网页

动词时态

发表于 2016-05-17   |  

动词时态

分成“时间”和“状态”,time 和 aspect

时间:过去、现在,未来

状态:主动,被动。。。动词后面的分词表示状态。

简单式

过去式

现在式

未来时间

完成式

名词词短语与冠词

发表于 2016-05-16   |  

名词词短语与冠词

名词短语

名词短语可以做主语,宾语,补语。

名词短语= 限定词+形容词+名词

a new book , 三部分,每一部分都可以省略。

什么时候不需要限定词?

名词复数
unmarried men

抽象名词
Honesty Fresh water

专有名词与补语位置

专有名词代表独一无二,所以仅不加a(an),暗示有另一个存在,也不加-s。
Genghis Khan Taibei Sunday

补语位置的专有名词,当补语和主语或宾语之间是同等关系时,补语也被当做专有名词

Mr.Chan was CTO of the group.

Clinton made Gorle campaign partner of the Presidential election.

定冠词the的用法

The可视为that或those的弱化。
当上下文有明指或暗示时,表示“那个”的指示功能,就要使用定冠词“the”。
He should be home,I saw light in his house.
turn off the portal light.

定冠词和专有名词

专有名词和定冠词是不能并存的,在意义上他们有冲突。
专有名词是世界上独一无二的东西,而定冠词却又明指或暗示有其他的存在。

This is not the John I know.
暗示有另一个John存在

例外不例外
海洋,山川,河流,岛屿被列为例外。
其实他们并不列外,只是省略了第三部分名词的名词短语。
The Pacific (Ocean)
The Atlantic (Ocean)
The Indian Ocean
The Mediterranean (Sea)
The Dead sea

The Alp

The Titanic (ship)

如果把这些名词短语的第三部还原,都是普通名词,可以加定冠词,来指示那个叫什么的海洋,山脉或船。

The United States of America
the United Nations

一、名词短语包括限定词、形容词、名词三部分。任一部分可以省略。
二、如果名词短语不加限定词,是因为该词不适合加a(an
).
三、a(an)是one的弱化结果,the是that/those的弱化结果。

我的新概念英语写作

发表于 2016-05-12   |  

MY NCE Journal

Lesson 58

Did he take the reward?

it was offerd to him, but he didn’t take.

Lesson 59

1. Word and Pattern

latch

He ran to the station, He wanted to catch the train

He ran to the station to catch the train.

2. Writing

1. dog veiw

I am a dog, My name is Rex.I used to live in a big house with a large garden.I liked to sit outside the front and bark.everytime I wanted to come into the garden I would bark until someone opened the gate. As the neighbours complained about my barks. My master spent weeks training me to press my paw on the latch to let myself in.I am very smart, I soon became an expert at opening the gate.but comparing opening the gate, I prefer to bark for someone to open the gate.so I found another way to do it.as soon as I opens the gate, I comes into the garden and waits until the gate shuts. Then I sits and barks until someone lets me outside, after this I immediately lets myself in and begins barking again.this gave me a great deal of pleasure.but soon my master’s wife found my secret, when she went outside shoping last week.she told this to my master, and then my master removed the gate.I got very anonyed, everytime I barked, no one would open the gate.I was very dissatifeid and left the big house and never come back.

2. Neighbours view

Our neighbour, Max, raised a dog years ago, it was call Rex, Rex used to sit outside the front gate and bark, evertime he wanted to come into the garden he would bark until someone opened the gate, even in the middlenight, I complained of the noisy many times to Max, he gave me a promise that he would sovle this. he spent weeks teaching Rex to open the gate by pressing his paw on the latch. Rex was a smart dog, he soon became an expert at opening the gate.However when I went by the Max’s house last week. I noticed that Rex was barking again, this time he was in the garden and waiting someone to let him outside! I immidately told Max about it. Max got anoyed , he removed the gate. Rex could never bark for someone to open the gate. Rex got anoyed, since then I have never seen Rex.

Lesson 60

foretell

I am visiting Mary this evenint

fortune-teller view

I am a fortune-teller, people call me Madam Bellinsky. I set up a tent in a village fair to make money.
yesterday a man visited me, he came into my tent and I told him to sit down. after he had put some money in my bowl, I looked into a crystal ball and tell him that a relative of his was coming to see him, she would be arriving this eveing and intends to stay for a few days. the moment he went outside, a beautifull woman he knows well would rush toward him, she would speak to him and lead him out of this plase, that is all I said to him.

as soon as he went outside, I totally forgot him and what I said. the following morning, he returned to my tent and told me all I had foretold correctly, as soon as he went outside, his wife hurried towards to him and asked him where he had been hiding, she had been looking for him all the afternoon, she told him that his sister would be here in less than an hour, they had to be at the station to meet her. they were late already. as she walked away, he followed her out of the fare.

writer’s wife view

my husband believes that fortune can be known by fortune-teller. a few days ago he visited a fortune-teller called Madam Bellinsky at a village fair. he went into the tent. it was dark inside. the fortune-teller told him to sit down, after he had given her some money, she asked him to keep queit while she was working,then she looked into a crystal ball and said: a relative of yours is comming to see you, she will be arriving this eveninng. she intends to stay for a few days. the moment you leave this tent, a woman you know well will rush toward you and speak to you. She will lead you out of this place. that is all. as soon as he went outside, he forgot all about Madam Bellinsky because I hurried towards to him, I had been looking for him for all the afternoon.”where have you been hiding” I asked impationtly. ‘your sister will be here in less than an hour, we must be at the station to meet her. we are late already’. as I walked away, he followed me out of the fair.

Lesson 61

distant
that is a distant thing, I can not remember.

How many projects have you completed now?
when I have finished this one, I will have completed ten.
How many books have you read now?
when I have read this one, I will have read 2 books.

astronaut’s view.

I’m an astronaut in USA, I am working at NASA, recently NASA lauched a telescope called Hubble into space. since then there was a trouble wiht the Hublle. the main mirror was fautly, the pictures it sent us were dispointing. so NASA is going to send four astronauts to repair it. the astronauts will take the shuttle Endeavour to the Hubble. the Endeavour will grab and hold the Hubble by a robot-arm while the astronauts repaires the Hubble.of course, the Hubble is outside of the earth’s atmosphere, so it will send us the clearest pictures of the stars and distant galaxies that we have ever seen. it will tell us about the age and size of the universe. by the time your read this, the Hubble will have sent us thousands and thousands of wonderful pictures.

NASA’s View

The Hubble was lauched into space on april 20, 1990, since then it has sent us thousands and thousands of wonderful pictures. The hubble is above the earth’s atmophere, so the pictures of the stars and distant galaxies are clearer than we have ever seen. our scientist can figure out the age and size of universe by these pictures. but there was a trouble with the Hubble right from the start, its main mirror has some problems since it was sent into space. so soon we sent four astronauts to repairs it.the shuttle Endeavour took the astronauts to the hubble. While the astronauts was making the neccessary repaires, the shuttle grabed and hold the Hubble.

lessson 62

desolate
some places are desolate in the west of china.

I had been studying for years befor I got this job.

villager’s view

I was living in a tiny village. one year, the forest fire started near our village. the firemen soon came to fight it. the fire was very fiere. after three weeks, the fire finally was under control by the firemen’s effort. but the great trees, which had been covering the ground for miles around, was burnt down, now smoke rose up from the ground over the hills.
the winter was coming, as the rain was heavy in the season, the hills threatoned our village with destruction, for the heavy rain would not only wash away the soil but would cause floods as well. when the fire had been put out, the forest authorites ordered several tons of a sepecail type of grass seed which would grow quickly. the seed was sprayed over the ground in huge quatities by planes. the planes had been planting seed for nearly a month when it began to rain, however, the grass had already taken root. in places of the great tree which had been growing there for centuries, pacthes of green had begun to appear in the blackened soil.

firemen’s view

last year we recived a call, there was a fire in the countryside. as soon as we had arrived, we began to fight the fire, the fire was firce. before we could get the fire under control, we had been fighting it for nearly three weeks. this is the longest fire time I had ever seen.
smoke rose up from the groud over the hills. there had been great tree for mils around befor the fire began. the winter was comming, the rain would be very heavy so that the floods would be caused. when we had at last put out the fire, the forest authorites ordered several tons of a special tpye of grass seed. the seed could grow quickly. the seed was sprayed over the ground in huge quatities by planes. the planes had been planting for nearly a month when it began to rain. In place of the great trees which had been growing for centuries, patches of green had begun to appear in the blackened soil.

Lesson 63

Jeremy’s view

I have a large circle of friends and I am very popular at parties. everybody admires me for my great sense of humour. everybody, that is. Except my six-year-old daughter, rencently I was asked to make a speech at a wedding reception by one of my closest freinds. this is the sort of thing I love, I prepared the speech carefully and went to the party with Jenny. I had included a large number of funny stories in the speech and, of course, it was great success. as soon as I had finished, Jenny told me that she wanted to go home, I was a little dispointed by this but I did as my daughter asked. on the way home, I asked her if she had enjoyed the speech. to my suprise, she said she hadn’t, then I asked why this was so, she told me that she did not like to see so many people laughing at me.

Jenny’s View

my father has a large circle of freinds and is very popular at parties. everybody admires him for his great sense of humour. except me. recentlly. one of his closest freinds asked him to make a speech at a wedding party, this is the sort of thing he loves. he prepared the speech carefully and went to the party with me. He had included a large number of funny stories and, of course, it was great success. but I felt very embarrassed, everbody had been laughing from the start. as soon as he had finshed, I told him that I wanted to go home. he was a little dispointed by this but he did as I asked. On the way home, he asked me if I had enjoyed the speech, I said I hadn’t, he was so suprise, then asked me why this was so, I told him that I did not like to see so many people laughing at him.

Lesson 64

Aime’s view

I am Aime from french. I am engneer. in 1858, I arrived in England. I had a plan for a twenty-one miles tunnel under the English Channel. in this plan a platform was possible to build in the center of the tunnel. it would serve as a port and railway station. the tall chimneys would be built above the sea level to make the tunnel well-ventilated. but the british thought my plas was not good enough. two year later, a better plan was put forwardd by an Englishman, Williams Low. He said a double railway shoud be built. it would sovle the problem of ventilation. for when a train enterd the tunnel. it would draw in fresh air behind it. though the plan was perfect, the tunnel was actually begun forty two years later. soon it was stoped, for the war began, the british feard the invasion. until I died I could not see the tunnel was begun again.

William’s View.

The Engish Channel is twenty-tow miles from Britain to French. It was possible to build a tunnel under it. recenlty a French engneer called Aime came to English with a plan for the tunnel. He suggested that it would be possible to build a platform in the centre of the Channel. Tall chemneys above the sea level would be built to sovle the problems of the ventilation. but the british did not agree the plan, for it is not posibble to build a lot of chimneys above the sea. Based on Aime’s plan, I designed another plan. in my plan I suggested that we should built a double railways. it would make the tunnel well-ventilated. because the trains would bring fresh air into the tunnel when it entered the tunnnel. but they refused my plan neither. forty-two years later a tunnel was begun, if the warfare had not begun and the british had not been afraid of the invasion, it would have been completed and conneted Britain and the European continent.

lesson 66

twenty-six years ago, a Lancaster bomber crashed on Wallis island in the south Pacific, the island is remote and a long way west of Samoa.
but over the years. the crash was forgotten and the wreck remained undisturbed. but the plane was accidentally rediscovered in an aerial survey of the island. By this time, a Lancaster bomber in reasonalbe condition was rare and worth rescueing. The French authorities had the plane packaged and moved in parts back to France. a group of enthusiasts are going to have the plane restored, it has four Rolls-Royce Merlin engines, but the group will need to have only three of them rebuilt. Imagine thier suprise and delight when they broke open the packing cases, the fourth engine was sweet as honey– still in perfect condition, a colony of bees had turned the engine into a hive and it was tottaly preserved in beeswax.

1…4567
陈群

陈群

ever-growing

65 日志
6 分类
11 标签
© 2016 陈群
由 Hexo 强力驱动
主题 - NexT.Pisces