1. string type

main(List<String> args) {
String name = "huhx";
changIt(name);
print('after: $name'); // after: huhx
} void changIt(String name) {
print('before: $name'); // before: huhx
name = "linux";
}

2. reference Type

class User {
String name; User(this.name);
} main(List<String> args) {
User user = User("huhx");
changIt(user);
print('after: ${user.name}'); // after: linux
} void changIt(User user) {
print('before: ${user.name}'); // before: huhx
user.name = "linux";
}

3. deep clone

import 'dart:convert';

class User {
String name; User(this.name); factory User.fromJson(Map<String, dynamic> userMap) => User(userMap['name']); Map<String, dynamic> toJson() => {'name': this.name}; User clone() {
final String jsonString = json.encode(this);
final jsonResponse = json.decode(jsonString); return User.fromJson(jsonResponse as Map<String, dynamic>);
}
} main(List<String> args) {
User user = User("huhx");
changIt(user);
print('after: ${user.name}'); // after: huhx
} void changIt(User user) {
User temp = user.clone();
// User temp = user; then: after linux
print('before: ${temp.name}'); // before: huhx
temp.name = "linux";
}

dart基础---->函数传值的更多相关文章

  1. js 基础 函数传值

    让我忽略的函数传值问题 function box(num){ num += 10;  // num(有色的num) 实际就是arguments[0] ,如果参数没有num,则函数体的num(有色的nu ...

  2. c#基础 函数传值

    随便新建个控制台程序做个演示! 1.最基础,最普通的传值方式: static void Main(string[] args) { ); Console.WriteLine("x:" ...

  3. [java学习笔记]java语言基础概述之函数的定义和使用&函数传值问题

    1.函数 1.什么是函数? 定义在类中的具有特定功能的一段独立小程序. 函数也叫做方法 2.函数的格式 修饰符   返回值类型    函数名(参数类型  形式参数1, 参数类型  形式参数2-) { ...

  4. 速战速决 (3) - PHP: 函数基础, 函数参数, 函数返回值, 可变函数, 匿名函数, 闭包函数, 回调函数

    [源码下载] 速战速决 (3) - PHP: 函数基础, 函数参数, 函数返回值, 可变函数, 匿名函数, 闭包函数, 回调函数 作者:webabcd 介绍速战速决 之 PHP 函数基础 函数参数 函 ...

  5. python基础——函数的参数

    python基础——函数的参数 定义函数的时候,我们把参数的名字和位置确定下来,函数的接口定义就完成了.对于函数的调用者来说,只需要知道如何传递正确的参数,以及函数将返回什么样的值就够了,函数内部的复 ...

  6. jquery的ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...

  7. python基础—函数嵌套与闭包

    python基础-函数嵌套与闭包 1.名称空间与作用域 1 名称空间分为: 1 内置名称空间   内置在解释器中的名称 2 全局名称空间   顶头写的名称 3 局部名称空间 2 找一个名称的查找顺序: ...

  8. python基础—函数装饰器

    python基础-函数装饰器 1.什么是装饰器 装饰器本质上是一个python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能. 装饰器的返回值是也是一个函数对象. 装饰器经常用于有切 ...

  9. iOS 基础函数解析 - Foundation Functions Reference

    iOS 基础函数解析 - Foundation Functions Reference 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名- ...

  10. (2.16)Mysql之SQL基础——函数

    (2.16)Mysql之SQL基础——函数 关键词:mysql函数,mysql自定义函数,mysql聚合函数,mysql字符串函数,mysql数值函数 1.自定义函数 -- (1)一般形式 creat ...

随机推荐

  1. 音标s ed

    1 p /s/ cups  2 t /s/ hats puts3 k /s/ cakes books desks works worked /t/4 f /s/ roofssiz ziz s加其他清辅 ...

  2. openEuler22.09初始化脚本

    #!/bin/bash s=`nmcli d | grep "已断开" | awk '{print $1}'` echo /etc/sysconfig/network-script ...

  3. ES7-ES12总结篇

    脑图模式       插入 ES7-ES12  ES7  Array.prototype.includes()   includes() 方法用来判断一个数组是否包含一个指定的值,如果包含则 ...

  4. sql 字符串末尾空格不占长度

    print len('qwer ');--4 print len('qwer                            ');--4 print len('qwer ' + 't');-- ...

  5. ES2015常用知识点

    ES2015(又称ES6)部分1 let/const以及块作用域:2 循环语句 const arr=[1,2,3]; for(const item of arr){ console.log(item) ...

  6. npm安装时加 --save和不加的区别

    npm install xxx --save 命令是安装模块到项目node_modules目录下,会将模块依赖写入package.json文件中的dependencies{}下.如果将node_mod ...

  7. SQL Server 2014 启动时提示:无效的许可证数据,需要重新安装

    路径:C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE 双击运行DDConfigCA.exe后,Sql Server 20 ...

  8. Git在使用过程中遇到的一些问题

    git默认对文件中的大小写不敏感. 方案1: 通过配置git来达到识别文件大小写的问题.命令如下: git config core.ignorcecase false 缺点:每个仓库都需要修改. 方案 ...

  9. Istio思考往前一小步~系列一

    思考起源于现实应用需求,随着微服务理念普及,基础设施从单机到容器到Kubernetes,体验过集群的各种好处之后,我们还缺少什么?为什么还要在kubernetes的基础上部署Istio?个人认为Ist ...

  10. Adams:一种使接触力(力矩等等)失效的方法

    1 第一步:点击"运行脚本". 2 第二步:右击选择"仿真脚本",点击"创建". 3 第三步:选择"脚本类型"为&quo ...