program collections

Java

byte & 0xff


 byte[] b = new byte[1];
        b[0] = -127;

        System.out.println("b[0]:"+b[0]+"; b[0]&0xff:"+(b[0] & 0xff));

//output:b[0]:-127; b[0]&0xff:129

计算机内二进制都是补码形式存储:

b[0]: 补码,10000001(8bit)

b[0]int输出:int(32bit),补位1。11111111 11111111 11111111 10000001(32bit)
和原数一致

b[0]&0xff:11111111 11111111 11111111 10000001(32bit) & 11111111 =
00000000 00000000 00000000 10000001

低精度转成高精度数据类型,有两种扩展方案。(1)补零扩展 (2)符号位扩展

对于正数两种是一样的。

  • 使用补零扩展能够保证二进制存储的一致性,但不能保证十进制值不变

  • 使用补符号位扩展能够保证十进制值不变,但不能保证二进制存储的一致性

对于有符号类型,Java使用的是补符号位扩展,这样能保证十进制的值不变

return break

break is used to exit (escape) the for-loop, while-loop, switch-statement that you are currently executing.
return will exit the entire method you are currently executing (and possibly return a value to the caller, optional).

inputstream byte[] to String


byte[] buffer = new byte[17];
                    if (is != null) {
                        int size = is.read(buffer);
                        if(size > 0 ){
                            String Str = new String(buffer,0,size);
                        }
                    }

Stm32 send packet


        byte[] packet = new byte[len];
        packet[0] = (byte) type;
        packet[1] = (byte) len;
        packet[2] = (byte) seq;
        packet[3] = (byte)(isreset?1:0);
        packet[4] = (byte) vx;
        packet[5] = (byte)(vx >>8);
        packet[6] = (byte) vy;
        packet[7] = (byte)(vy >>8 );
        
       // 
        System.arraycopy(command.toDatas(), 0, packet, 3, command.getLen());


       int Seq = (datas[0]&0XFF);
       int vx = (datas[1]&0XFF) | ((datas[2])<<8));
       int Vy = ((datas[3]&0XFF) | ((datas[4])<<8));
       boolean Motostatel = ((datas[4] & (1 << 1))!=0);
       boolean Motostater = ((datas[4] & (1 << 2))!=0);
  • System.arraycopy(Object src,int srcPos,Object dest,int destPos,int length)

  • src:源数组

  • srcPos:源数组起始位置

  • dest:目标数组

  • destPos:目标数组起始位置

  • length:长度

Tips: srcdest是要可以互相转换或是同类型的数组

Tips:

可以自己复制自己


int[] src ={0,1,2,3,4,5,6}; 

System.arraycopy(src,0,src,3,3);

// output:{0,1,2,0,1,2,6}

生成一个长度为length的临时数组,将fun数组中srcPos
srcPos+length-1之间的数据拷贝到临时数组中,再执行System.arraycopy(临时数组,0,fun,3,3)

new Semaphore(0)


Semaphore semaphore = new Semaphore(0);

try {
                semaphore.acquire();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

//semaphore.release();

初始化信号量为0,semaphore.acquire()线程会阻塞。直到semaphore.release()之后 信号量变为1。

mysql

1045 access denied for user 'root'@'localhost' using password yes

忘记localhost密码,密码错误

  • step1,找到mysql安装目录下my.ini。在[mysql]下添加 skip-grant-tables

  • step2,重启mysql服务

  • step3,以管理员身份运行 cmd. 输入mysql -u root -p,直接回车

  • step4,输入use mysql

  • step5,mysql 5.6以前的,输入UPDATE mysql.user SET Password=PASSWORD('123456') WHERE User='root';

    mysql 5.6以后的,输入UPDATE mysql.user SET authentication_string=PASSWORD('root') WHERE USER='root';

Android

权限

root

linux系统中是只有root权限普通权限,root即是最高权限。

Android获取root其实和Linux获取root权限一样。Linux下获取root权限的时候就是执行sudo或者su

Android本身就不想让你获得Root权限,大部分手机出厂的时候根本就没有su这个程序。所以你想获得Android的root权限,第一步就是要把编译好的su文件拷贝到Android手机的/system/bin或者/system/xbin/目录下。接下来你可以在Android手机的adb shell或者串口下输入su了。

getColor() 过时


// 过时
textView.setTextColor(getResources().getColor(R.color.text_color));

textView.setTextColor(ContextCompat.getColor(this,R.color.text_color));

Installation error:INSTALL_FAILED_UID_CHANGED

尝试通过ADB删除产生冲突的数据文件


adb rm -rf /data/data/<your.package.name>

setHeight no use

当设置的高度比原来默认的高度要小时,调整setHeight是不生效的。


editText=(EditText)findViewById(R.id.myEditText);

// editText.setHeight(10); //不生效

editText.getLayoutParams().height = 100; 

Installation error:INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

1.1 包名大写了

2.2 缺少AndroidManifest.xml文件

Error:Error converting bytecode to dex

1.1 包重复

2.2 build本身问题, 只需要clean and rebuild 一下

EditText光标颜色

EditText 有一个属性 android:textCursorDrawable 用来控制光标的颜色。android:textCursorDrawable="@null","@null"作用是让光标颜色和text color一样

发现了以元素'd:skin'开头的无效内容

把有问题的devices.xml删除,在Android SDK 里面的tool\lib 下找到devices.xml拷贝到那个文件夹。

finished with non-zero exit value 2

重复的jar包,删除引用的包,同时删除modulebuild.gradle文件的引用。

border


<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#418bdc"/>
    <corners android:radius="2dp"/>
    <stroke android:width="2dp" android:color="#303f9f"/>
    <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" />
</shape>

VideoView播放视频无法全屏问题

重写VideoView


import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

/**
 * Created by lijingnan on 12/04/2017.
 */
public class CustomerVideoView extends VideoView {

    public CustomerVideoView(Context context) {
        super(context);
    }

    public CustomerVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomerVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // 其实就是在这里做了一些处理。
        int width = getDefaultSize(0, widthMeasureSpec);
        int height = getDefaultSize(0, heightMeasureSpec);
        setMeasuredDimension(width, height);
    }
}

退出程序

  • KillProcess

  //结束当前程序的进程  
  android.os.Process.killProcess(android.os.Process.myPid());

Tips:android中所有的activity都在主进程中,在Androidmanifest.xml中可以设置成启动不同进程,Service不是一个单独的进程也不是一个线程。

当你Kill掉当前程序的进程时也就是说整个程序的所有线程都会结束,Service也会停止,整个程序完全退出。

  • System.exit

//0表示正常退出,1表示异常退出(只要是非0的都为异常退出),即使不传0也可以退出,该参数只是通知操作系统该程序是否是正常退出
System.exit(0),System.exit(1)

Can't create handler inside thread that has not called Looper.prepare()

Handler对象与其调用者在同一线程中,如果在Handler中设置了延时操作,则调用线程也会堵塞。每个Handler对象都会绑定一个Looper对象,每个Looper对象对应一个消息队列(MessageQueue)。如果在创建Handler时不指定与其绑定的Looper对象,系统默认会将当前线程的Looper绑定到该Handler上。

在主线程中,可以直接使用new Handler()创建Handler对象,其将自动与主线程的Looper对象绑定;在非主线程中直接这样创建Handler则会报错,因为Android系统默认情况下非主线程中没有开启Looper,而Handler对象必须绑定Looper对象。

1.手动开启Looper,然后将其绑定到Handler对象上


final Runnable runnable = new Runnable() {
  @Override
  public void run() {
    //执行耗时操作
    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
  }
};
new Thread() {
  public void run() {
    Looper.prepare();
    new Handler().post(runnable);//在子线程中直接去new 一个handler
    Looper.loop();    //这种情况下,Runnable对象是运行在子线程中的,可以进行联网操作,但是不能更新UI
  }
}.start();

2.通过Looper.getMainLooper(),获得主线程的Looper


final Runnable runnable = new Runnable() {
  @Override
  public void run() {
    //执行耗时操作
    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
  }
};
new Thread() {
  public void run() {
    new Handler(Looper.getMainLooper()).post(runnable);
    //这种情况下,Runnable对象是运行在主线程中的,不可以进行联网操作,但是可以更新UI
  }
}.start();

xxx is not an enclosing class

  • 一般出现在内部类中,若要创建内部类的实例,需要有外部类的实例才行,或者是将内部类设置为静态的,添加 static 关键字

public class A {  
    public class B {  
          
    }  
}

A a = new A();  
A.B ab = a.new B();  

there is no default constructor available in ...

子类中使用了无参构造方法,而它的父类中至少有一个没有无参的构造方法。

  • 如果一个类没有构造方法,会有一个默认的无参构造方法。
  • 如果显示的定义了带参构造方法则默认的无参构造方法就会失效。

  • 一个类只要有父类,那么在它实例化的时候,一定是从顶级的父类开始创建

子类使用无参构造函数创建子类对象时,会去先递归调用父类的无参构造方法,这时候如果某个类的父类没有无参构造方法就会出错

错误实例:


public class Parent{

        int aga;

        public Parent(int age){
            this.aga = age;
        }
    }

    public class Child extends Parent{

        public Child(){
          /*
           * 默认调用父类的无参构造方法 
           * super();
           */
        }
    }

如果子类使用带参参构造函数创建子类对象时,没有使用super先调用父类的带参构造方法,这时默认会调用父类的无参构造方法,如果父类没有也会报错

错误实例:


public class Parent{

        int aga;

        public Parent(int age){
            this.aga = age;
        }
    }

    public class Child extends Parent{

        public Child(int age){
          /*
           * 默认调用父类的无参构造方法 
           * super();
           */
        }
    }

上述也可以在子类调用父类的有参构造函数


 public class Child extends Parent{

        public Child(int age){
        super(age);
        }
    }

JFinal

javax.servlet.ServletContext

BUG :The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required

Solution: 把tomcat/lib目录中的jsp-api.jarservlet-api.jar导入到项目的web/lib目录下。

cast

BUG :Jfinal Db.findFirst java.lang.Long cannot be cast to java.lang.Integer

Solution:return Db.findFirst(sql).getLong("count").intValue();

错误: 编码GBK的不可映射字符

BUG : eclipse导出javadoc时的错误: 编码GBK的不可映射字符

Solution:-encoding UTF-8 -charset UTF-8

solution

JavaScript

数组删除元素


          var arr = [1,2,3,4];
        arr.splice(1,1);
        /**
         * Array(3)
         * 0:1
         * 1:3
         * 2:4
         */
          
          var arr = [1,2,3,4];
        delete arr[1];
        /**
         * Array(3)
         * 0:1
         * 1:undefined
         * 2:3
         * 3:4
         */

delete arr[1],arr[1]变为undefined,数组的索引也保持不变

不要使用包装对象来创建原始类型变量

在js中我们可以使用String()Number()Boolean()构造函数来显式的创建包装对象


// String("test") , 一个字符串对象
// Number(5),一个数值对象
// Boolean(false),一个布尔对象

// Don't do it!

var x = new Boolean(false);
if (x) {
  alert('hi');  // Shows 'hi'.
}


var x = Boolean(0);
if (x) {
  alert('hi');  // This will never be alerted.
}
typeof Boolean(0) == 'boolean';
typeof new Boolean(0) == 'object';

script文件异步加载

<script src="path/to/myModule.js" defer></script>
<script src="path/to/myModule.js" async></script>

<script>标签打开defer或async属性,脚本就会异步加载。渲染引擎遇到这一行命令,就会开始下载外部脚本,但不会等它下载和执行,而是直接执行后面的命令。

  • defer与async的区别是:defer要等到整个页面在内存中正常渲染结束(DOM 结构完全生成,以及其他脚本执行完成),才会执行;async一旦下载完,渲染引擎就会中断渲染,执行这个脚本以后,再继续渲染。一句话,defer是“渲染完再执行”,async是“下载完就执行”。另外,如果有多个defer脚本,会按照它们在页面出现的顺序加载,而多个async脚本是不能保证加载顺序的。

cookie只区分域名,不管端口

  • cookie安全

1.1 httponly:设置了httponly属性,无法通过脚本获取到cookie信息

2.2 secure:设置了secure属性,cookie只能通过https安全传输,并不会通过未加密的http连接发送

3.3 sameSite:目前只有chrome和firefox支持,用于定义cookie如果跨域发送

debug

debugger

可以在JavaScript手动添加断点


debugger;
DOM
  • 右击DOM元素,'Force Element State',展开子菜单可以看到几种常见的伪类::active, :hover, :focus, and :visited。可以调试伪类。

  • 右击DOM元素,可以看到一个名为Break on的选项,展开有Subtree Modifications,Attributes Modifications以及Node Removal三个选项。(当JS尝试改变DOM元素时,给元素添加的断点便会触发。)

a) Subtree Modifications,当添加,改变,删除子元素时触发

b) Attributes Modifications,当元素属性被改变时触发

c) Node Removal,当移除元素时触发

Audits

Audits可以检查页面的性能方面存在的问题,并给出优化意见

Jquery

Cannot read property 'msie' of undefined

原因是$.browser这个api从jQuery1.9开始就正式废除,js代码里只要用到$.browser就会报这个错。

jQuery官方说明

1.1 可以替换成1.9之前的版本

2.2 使用插件jQuery Migrate,这个插件会恢复在更新版本中废弃的API

3.3 在jQuery文件之后,$.browser的代码之前 加载以下代码


jQuery.browser={};(function(){jQuery.browser.msie=false; jQuery.browser.version=0;if(navigator.userAgent.match(/MSIE ([0-9]+)./)){ jQuery.browser.msie=true;jQuery.browser.version=RegExp.$1;}})();

$.ajax

data封装不加入JSON.stringify(data),会变成字符串拼接,'name=vinxent&age=21',有点和get方法相像。

若使用JSON.stringify(data),则会传输json对象'{name;'vinxent', age:21}'。

所以,在一般场景来说,get方法无需JSON.stringify,post方法需要。

Jquery动态绑定事件


//Jquery绑定事件

$('.div').click(function(){});

//Jquery动态绑定事件

$('.div').on('click',function(){});

<-- 当页面动态刷新时,新加载的元素依然可以绑定事件 -->

$(document).on('click','.div',function(){});

Jquery on绑定hover事件

不能用on处理hover事件,因为Jqueryhover事件是一个封装的事件,不是真正的事件。

所以使用mouseentermouseleave来代替鼠标悬浮和离开事件。


$(document).on('mouseenter', '.div', function() {
});

$(document).on('mouseleave', '.div', function() {
});

Jquery获取时间并且格式化


Date.prototype.format = function(format) {
    /*
     * eg:format="YYYY-MM-dd hh:mm:ss";

     */
    var o = {
        "M+" :this.getMonth() + 1, // month
        "d+" :this.getDate(), // day
        "h+" :this.getHours(), // hour
        "m+" :this.getMinutes(), // minute
        "s+" :this.getSeconds(), // second
        "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
        "S" :this.getMilliseconds()
    // millisecond
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
    }
    for ( var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                    : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

var startTime = new Date().format("yyyy-MM-dd 00:00:00");
var endTime = new Date().format("yyyy-MM-dd hh:mm:ss");

滚动条滚动底部

  • scrollTop([val]) 获取匹配元素相对滚动条顶部的偏移。

  • scrollLeft([val]) 获取匹配元素相对滚动条左侧的偏移。

  • scrollHeight 滚动条高度


$(".div").scrollTop( $(".div")[0].scrollHeight);

Jquery size( )和length

size()jQuery 提供的函数,而 length是属性。两者的取值是一样的。

页面之间传值


   //页面一
   location.href = "href2.html?id=3";
   //页面二
   var _url = document.URL;
   var _urlParam = _url.split('?')[1];
   var _value = _urlParam.split('=')[1];

也可以使用jquery.params.js $.query.get("id");

### 灵活运用三目运算符

 
 (_list.equipStatus ==1?"运行中":(_list.repairStatus ==2?"维修中":"待确认"))
 

正确引用jQuery

  1. 尽量在body结束前才引入jQuery,而不是在head中。
    2.借助第三方提供的CDN来引入jQuery,同时注意当使用第三方CDN出现问题时,要引入本地的jQuery文件。
    3.如果在</body>前引入script文件的话,就不用写document.ready,因为这时执行js代码时DOM已经加载完毕了。

<body>  
    <script src="http://lib.sinaapp.com/js/jquery11/1.8/jquery.min.js"></script>  
    <script>window.jQuery  document.write('<script src="jquery1.8.min.js">\x3C/script>')</script>  
</body> 

优化jQuery选择器


<div id="nav" class="nav">  
    <a class="home" href="http://www.jquery001.com">jQuery学习网</a>  
    <a class="articles" href="http://www.jquery001.com/articles/">jQuery教程</a>  
</div>

如果我们选择class为home的a元素时,可以使用下边代码:

$('.home'); //1

$('#nav a.home'); //2

$('#nav').find('a.home'); //3

  1. 方法1,会使jQuery在整个DOM中查找class为home的a元素,性能可想而知。
    2.方法2,为要查找的元素添加了上下文,在这里变为查找id为nav的子元素,查找性能得到了很大提升。
    3.方法3,使用了find方法,它的速度更快,所以方法三最好。

关于jQuery选择器的性能优先级,ID选择器快于元素选择器,元素选择器快于class选择器。因为ID选择器和元素选择器是原生的JavaScript操作,而类选择器不是。

缓存jQuery对象

缓存jQuery对象可以减少不必要的DOM查找,关于这点大家可以参考下缓存jQuery对象来提高性能。


// 糟糕
h = $('#element').height();
$('#element').css('height',h-20);

// 建议
$element = $('#element');
h = $element.height();
$element.css('height',h-20);
使用子查询缓存的父元素

正如前面所提到的,DOM遍历是一项昂贵的操作。典型做法是缓存父元素并在选择子元素时重用这些缓存元素。


// 糟糕
var
    $container = $('#container'),
    $containerLi = $('#container li'),
    $containerLiSpan = $('#container li span');
// 建议 (高效)
var
    $container = $('#container '),
    $containerLi = $container.find('li'),
    $containerLiSpan= $containerLi.find('span');
精简jQuery代码

一般来说,最好尽可能合并函数。


// 糟糕
$first.click(function(){
    $first.css('border','1px solid red');
    $first.css('color','blue');
});
// 建议
$first.on('click',function(){
    $first.css({
        'border':'1px solid red',
        'color':'blue'
    });
});
减少DOM操作
最小化DOM更新

重布局和重绘是WEB页面中最常见的也是最昂贵的两种操作。
当改变样式,而不改变页面几何布局时,将会发生重绘。隐藏一个元素或者改变一个元素的背景色时都将导致一次重绘。
当对页面结构进行更新时,将导致页面重布局。


    //糟糕
    for(var i=0; i<10000; i++){
    $("#main table").append("<tr><td>aaaa</td></tr>");
    }
    //建议
    var tablerow = "";
    for(var i=0; i<10000; i++){
    tablerow  += "<tr><td>aaaa</td></tr>";
    }
$("#main table").append(tablerow);
prop和attr方法

对于元素自身的固有属性 使用 prop 对于自定义的属性使用attr方法

例:获取选中的checkbox的value值


    $("input[type=checkbox]").each(function() {

                    if(true == $(this).prop("checked")) {
                    
                        alert($(this).attr("value"));
                        
                    }
                });
each遍历

each实现全选或是取消全选。


    $("#selectAll").click(function() {
    
                if($("#selectAll").prop("checked")) {
                    $("#selectAll input[type=checkbox]").each(function() {
                        $(this).prop("checked", "true");
                    });
                    
                } else {
                
                    $("#selectAll input[type=checkbox]").each(function() {
                        $(this).removeAttr("checked");
                    });
                }
            });

layer.js

父页面和子页面传值

1.1 访问父页面值


// "id" 父页面元素
var parentId=parent.$("#id").val();

2.2 访问父页面方法


var parentMethod=parent.getMethod();

3.3 给父页面传值


    // "id" 父页面元素
    parent.$('#id').text('');
    

4.4 关闭弹出的子页面窗口


//获取窗口索引  

var index = parent.layer.getFrameIndex(window.name); 

//关闭弹出的子页面窗口  

parent.layer.close(index);

5.5 子页面调用父页面刷新


parent.location.reload();

uploadify.js

error placeholder element

这是因为input 元素必须有id,并且用id初始化uploadify函数。否则就报错。

chart.js

Uncaught TypeError: Cannot read property 'length' of null

这个问题是因为js代码执行的时候canvas还没有被创建。可以将初始化图表代码片段放到window.onload后面


window.onload = function() {
  var ctx = document.getElementById("myChart");
  var lineChart = new Chart(ctx, {
    type: 'line',
    data: {
      labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
      datasets: [{
        label: "2015",
        data: [10, 8, 6, 5, 12, 8, 16, 17, 6, 7, 6, 10]
      }]
    }
  })
}

The problem is that when your code executes, the canvas has not been created yet. You should wrap your code inside a function and assign that function to window.onload event. You can see the sample code below.

Cannot read property 'transition' of null

Try to call mychart.update() after setting the new data... that solved the problem for me.

Browser

Slow network is detected. Fallback font will be used while loading

新版本的Chrome在网络环境较差的时候会在控制台输出Slow network is detected. Fallback font will be used while loading,但有时会对调试造成不便,可以在chrome配置中禁用该项: 

地址栏输入chrome://flags/#enable-webfonts-intervention-v2,并设置为Disabled;重启Chrome。

AngularJS

$sce

$sce is included by default starting with angular 1.2- so you don't need sanitize anymore in order to get $sce. So, with 1.2, you can pass $sce in as any other service. But make sure your angular is version 1.2 (in case you checked the sanitize version vs core).

获取body元素


// $document 服务

$document[0].body

angular.element(document).find('body')

1487780-20181018105344395-2049328884.png

防抖动输入


<body ng-controller="myCtrl">
        <div ng-app="App" ng-controller="Ctrl" class="app">
            <button ng-click="inc()">Add</button>
            <span>{{ val }}</span>
        </div>
        <script>
            angular.module("App", []).controller("Ctrl", ['$scope', '$debounce', function($scope, $debounce) {
                        $scope.shouldBeFocus = true;
                        $scope.val = 0;
                        $scope.inc = function() {
                            $debounce(increase, 300);
                        };

                        var increase = function() {
                            $scope.val++;
                        }

                    }]).factory('$debounce', ['$rootScope', '$browser', '$q', '$exceptionHandler',
                        function($rootScope, $browser, $q, $exceptionHandler) {
                            var deferreds = {},
                                methods = {},
                                uuid = 0;

                            function debounce(fn, delay, invokeApply) {
                                var deferred = $q.defer(),
                                    promise = deferred.promise,
                                    skipApply = (angular.isDefined(invokeApply) && !invokeApply),
                                    timeoutId, cleanup,
                                    methodId, bouncing = false;

                                // check we dont have this method already registered
                                angular.forEach(methods, function(value, key) {
                                    if(angular.equals(methods[key].fn, fn)) {
                                        bouncing = true;
                                        methodId = key;
                                    }
                                });

                                // not bouncing, then register new instance
                                if(!bouncing) {
                                    methodId = uuid++;
                                    methods[methodId] = {
                                        fn: fn
                                    };
                                } else {
                                    // clear the old timeout
                                    deferreds[methods[methodId].timeoutId].reject('bounced');
                                    $browser.defer.cancel(methods[methodId].timeoutId);
                                }

                                var debounced = function() {
                                    // actually executing? clean method bank
                                    delete methods[methodId];

                                    try {
                                        deferred.resolve(fn());
                                    } catch(e) {
                                        deferred.reject(e);
                                        $exceptionHandler(e);
                                    }

                                    if(!skipApply) $rootScope.$apply();
                                };

                                timeoutId = $browser.defer(debounced, delay);

                                // track id with method
                                methods[methodId].timeoutId = timeoutId;

                                cleanup = function(reason) {
                                    delete deferreds[promise.$$timeoutId];
                                };

                                promise.$$timeoutId = timeoutId;
                                deferreds[timeoutId] = deferred;
                                promise.then(cleanup, cleanup);

                                return promise;
                            }

                            // similar to angular's $timeout cancel
                            debounce.cancel = function(promise) {
                                if(promise && promise.$$timeoutId in deferreds) {
                                    deferreds[promise.$$timeoutId].reject('canceled');
                                    return $browser.defer.cancel(promise.$$timeoutId);
                                }
                                return false;
                            };

                            return debounce;
                        }
                    ]);;
        </script>
    </body>

this in AngularJS


angular.module("App", []).controller("Ctrl", function($scope) {
                       // this controller
                        console.log("controller",this);
                        
                        $scope.foo = function() {
                                                  // this scope
                                  console.log("foo",this);
                        };
                        var foo2 = function() {
                                                  // this windows
                                 console.log("foo2",this);
                        }
                        
                        $scope.foo();
                        foo2();
                    });

1487780-20181019153511051-584357084.png

angular.copy() angular.extend()

angular.copy(source, [destination]); // source: copy的对象. 可以使任意类型, 包括null和undefined. destination:接收的对象 返回复制或更新后的对象

  • 如果省略了destination,一个新的对象或数组将会被创建出来;

  • 如果提供了destination,则source对象中的所有元素和属性都会被复制到destination中;

  • 如果source不是对象或数组(例如是null或undefined), 则返回source;

  • 如果source和destination类型不一致,则会抛出异常。

angular.extend(destination, source);

  • 复制src对象中的属性到dst对象中. 支持多个src对象. 如果你不想改变一个对象,你可以把dst设为空对象{}: var object = angular.extend({}, object1, object2).

  • 注意: angular.extend不支持递归复制.

Git

push 需要输入用户名和密码

换成ssh方式


git remote -v 

// origin https://github.com/xxxxxx/xxxx.git (fetch)
// origin https://github.com/xxxxxx/xxxx.git (push)

git remote rm origin

git remote add origin git@github.com:xxxxx/xxxx.git

git push origin

git默认用notepad++ 打开


git config --global core.editor "'D:\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin '$*'"

npm

npm WARN saveError ENOENT: no such file or directory ... package.json

npm init -f

生成一个package.json

React

render(, document.body);

warning.js:36 Warning: render(): Rendering components directly into document.body is discouraged, since its children are often manipulated by third-party scripts and browser extensions. This may lead to subtle reconciliation issues. Try rendering into a container element created for your app.


ReactDOM.render(<Greeter />, document.getElementById('react_container'));

转载于:https://www.cnblogs.com/chenjy1225/p/9661237.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值