# 2016年4月18日

\[TOC]

## 2016年4月18日

### javascript

JavaScript的原生错误类型

* SyntaxError
  * SyntaxError是解析代码时发生的语法错误。
* ReferenceError
  * ReferenceError是引用一个不存在的变量时发生的错误。
  * 另一种触发场景是，将一个值分配给无法分配的对象，比如对函数的运行结果或者this赋值。
* RangeError
  * RangeError是当一个值超出有效范围时发生的错误。主要有几种情况，一是数组长度为负数，二是Number对象的方法参数超出范围，以及函数堆栈超过最大值。
* TypeError
  * TypeError是变量或参数不是预期类型时发生的错误。比如，对字符串、布尔值、数值等原始类型的值使用new命令，就会抛出这种错误，因为new命令的参数应该是一个构造函数。
* URIError
  * URIError是URI相关函数的参数不正确时抛出的错误，主要涉及encodeURI()、decodeURI()、encodeURIComponent()、decodeURIComponent()、escape()和unescape()这六个函数。
* EvalError
  * eval函数没有被正确执行时，会抛出EvalError错误。该错误类型已经不再在ES5中出现了，只是为了保证与以前代码兼容，才继续保留。

### angularjs

#### $cacheFactory缓存服务

* info()
  * 缓存内容信息
* put()
  * 设置缓存
* get()
  * 获取缓存
* remove()
  * 删除缓存
* 配置capacity
  * 设置缓存长度

```javascript
m1.controller('Acon',['$scope','$cacheFactory',function($scope,$cacheFactory){
    var cache=$cacheFactory('myCache');

    console.log(cache.info());

    cache.put('name','hello');
    cache.put('age','20');

    console.log(cache.get('name'));
}])
```

#### $log服务

* log()
  * 打印
* info()
  * 打印信息
* warn()
  * 警告信息
* error()
  * 错误信息

```javascript
m1.controller('Aaa',['$scope','$log',function($scope,$log){

    $log.log('hello');
    $log.info('hello');
    $log.warn('hello');
    $log.error('hello');
}]);
```

![](/files/-LjTb9IqfmaKkYoGkJRk)

#### $interpolate

插值计算

```markup
<script>
var m1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope','$interpolate',function($scope,$interpolate){ 
    $scope.$watch('body',function(newBody){     
        if(newBody){
            var temp = $interpolate(newBody);
            $scope.showText = temp({ name : $scope.name });         
        }       
    }); 
}]);
</script>

<div ng-controller="Aaa">
    <input type="text" ng-model="name">
    <textarea ng-model="body">
    </textarea>
    <p>{{showText}}</p>
</div>
```

#### 供应商概念

* 服务的相关初始配置操作
* config
  * provider
  * $interpolate
    * startSymbol()
      * 表达式头部标识
    * endSymbol()
      * 表达式尾部标示
  * $log
    * debugEnabled()
      * 禁用某功能
  * $anchorScroll
    * disableAutoScrolling()
      * 禁止在地址栏自动跳转

#### **$q**延迟对象

* promise的实现
* defer()
* resolve()
  * 成功
* reject()
  * 失败
* notify()
* then()

#### 自定义服务

* module
  * filter()
  * directive()
  * factory()
  * provider()
    * 区别
    * $get

```javascript
var m1 = angular.module('myApp',[]);
m1.factory('myService',function(){

    return {
        name:'efee',
        show:function(){
            return this.name+':angular';
        }
    }
})
m1.controller('Acon',['$scope','myService',function($scope,myService){
    console.log(myService.show());
}])
```

* 模块之间的通信
  * provide好处
* service()
  * 构造函数
* constant()
  * 设置常量
* value()
  * 区别

#### angularjs插件

* ngSanitize
* ngRoute
  * 版本的问题
  * ng-view
    * 这个插件特有。
  * $routeProvider
    * when
      * template
      * templateUrl


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://note.niefee.com/summary/4/2016-nian-4-yue-18-ri.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
