{"id":553,"date":"2023-02-01T21:44:02","date_gmt":"2023-02-01T13:44:02","guid":{"rendered":"http:\/\/gjweb.top\/?p=553"},"modified":"2023-02-01T21:44:03","modified_gmt":"2023-02-01T13:44:03","slug":"04-%e7%b1%bb%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=553","title":{"rendered":"04. \u7c7b\u7684\u4f7f\u7528"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"\u58f0\u660e\u7c7b-\u540c-js\">\u58f0\u660e\u7c7b ( \u540c JS )<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person{<br> &nbsp; &nbsp;String name = \"zhangsan\",<br> &nbsp; &nbsp;void getInfo(){}<br>}<br>var person = new Person()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\">\u9ed8\u8ba4\u6784\u9020\u51fd\u6570<\/h2>\n\n\n\n<p>\u5f62\u5f0f\u540c JS \u7684 Contructor<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person{<br> &nbsp; &nbsp;Person(){<br> &nbsp; &nbsp; &nbsp; &nbsp;\/\/ new Person \u7684\u65f6\u5019\u4f1a\u7acb\u5373\u8c03\u7528\u8be5\u65b9\u6cd5<br> &nbsp;  }<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u547d\u540d\u6784\u9020\u51fd\u6570\">\u547d\u540d\u6784\u9020\u51fd\u6570<\/h2>\n\n\n\n<p>\u5982\u679c\u5728\u5b9e\u4f8b\u5316\u4e3b\u52a8\u8c03\u7528\u4e86\u547d\u540d\u6784\u9020\u51fd\u6570,\u5c06\u4e0d\u4f1a\u89e6\u53d1\u9ed8\u8ba4\u7684\u6784\u9020\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person{<br>    Person.now()<br>}<br>var  xxx = new Person.now();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5355\u72ec\u62bd\u79bb-class\">\u5355\u72ec\u62bd\u79bb class<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import \"lib\/xxx.dart\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u79c1\u6709\u65b9\u6cd5\u548c\u79c1\u6709\u5c5e\u6027\">\u79c1\u6709\u65b9\u6cd5\u548c\u79c1\u6709\u5c5e\u6027<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Dart \u4e2d\u53d8\u91cf\u524d\u9762 &#8220;_&#8221; \u8868\u793a\u79c1\u6709<\/li><li>\u5355\u72ec\u628a\u8be5\u7c7b\u62bd\u79bb\u4e3a\u4e00\u4e2a\u5355\u72ec\u6587\u4ef6,\u79c1\u6709\u5c5e\u6027\u624d\u80fd\u751f\u6548<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"getter-\u548c-setter-\u7684\u7528\u6cd5\">getter \u548c setter \u7684\u7528\u6cd5<\/h2>\n\n\n\n<p>\u5f53\u5c5e\u6027\u548c\u65b9\u6cd5\u5e26\u6709 get \u548c set \u5c5e\u6027\u662f \u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7 &#8220;.&#8221; \u64cd\u4f5c\u7b26\u8bbf\u95ee\uff0c\u65e0\u9700\u52a0\u5165 &#8220;()&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person{<br> &nbsp; &nbsp;String name = \"\";<br> &nbsp; &nbsp;Person(this.name);<br> &nbsp; &nbsp;get getName{return this.name};<br> &nbsp; &nbsp;set setName(val){}this.name = val}<br>}<br>main(){<br> &nbsp; &nbsp;var test = new Person(\"xxx\")<br> &nbsp; &nbsp;text.getName \/\/ \u5f20\u4e09<br> &nbsp; &nbsp;text.setName = \"aaa\"<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7c7b\u7684\u521d\u59cb\u5316\u5217\u8868\">\u7c7b\u7684\u521d\u59cb\u5316\u5217\u8868<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person{<br> &nbsp; &nbsp;String name;<br> &nbsp; &nbsp;int age;<br> &nbsp; &nbsp;Person():name=\"zhangsan\",age=18{} \/\/ \u5b9e\u4f8b\u5316\u4e4b\u524d\u590d\u5236<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7c7b\u7684\u9759\u6001\u6210\u5458\">\u7c7b\u7684\u9759\u6001\u6210\u5458<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f7f\u7528 static \u5173\u952e\u5b57\u6765\u5b9e\u73b0\u53d8\u91cf\u548c\u51fd\u6570<\/li><li>\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u8bbf\u95ee\u975e\u9759\u6001,\u8d39\u9759\u6001\u53ef\u4ee5\u8bbf\u95ee\u9759\u6001<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7c7b\u4e2d\u7684\u4fee\u9970\u7b26\">\u7c7b\u4e2d\u7684\u4fee\u9970\u7b26<\/h2>\n\n\n\n<p>as \u5f3a\u5236\u8f6c\u6362<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var P1 = \"\";<br>P1 = new Person();<br>(P1 as Person).xxx(); \/\/ \u5f3a\u5236\u5c06 p1 \u8f6c\u4e3a Person \u8c03\u7528\u5176\u7c7b\u4e2d\u7684\u65b9\u6cd5<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u8054\u673a\u64cd\u4f5c\u7b26\">.. \u8054\u673a\u64cd\u4f5c\u7b26<\/h2>\n\n\n\n<p>&#8220;.&#8221;\u4fee\u9970\u7b26\u7684\u8bed\u6cd5\u7cd6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var dome = new Dome();<br>dome..name = \"xxx\";<br>    ..age = 18;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7c7b\u7684\u7ee7\u627f\">\u7c7b\u7684\u7ee7\u627f<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b50\u7c7b\u4f7f\u7528 extends \u7ee7\u627f\u7236\u7c7b<\/li><li>\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u8bfe\u4ef6\u7684\u5c5e\u6027\u548c\u65b9\u6cd5,\u6784\u9020\u51fd\u6570\u9664\u5916<\/li><li>\u5b50\u7c7b\u53ef\u590d\u7528\u7236\u7c7b\u7684 get \u548c set<\/li><li>super \u5173\u952e\u5b57,\u7528\u4e8e\u5b50\u7c7b\u7ed9\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\u4f20\u53c2<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>child():super(xxx,xxx){}<br>child:super.xxx(xx,xx){}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5728\u590d\u5199\u7236\u7c7b\u65b9\u6cd5\u65f6\u52a0\u4e0a @override\u65b9\u6cd5<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u62bd\u8c61\u7c7b\">\u62bd\u8c61\u7c7b<\/h2>\n\n\n\n<p>\u7528\u4e8e\u5b9a\u4e49\u6807\u51c6,\u5b50\u7c7b\u53ef\u4ee5\u7ee7\u627f\u62bd\u8c61\u7c7b\u4e5f\u53ef\u4ee5\u5b9e\u73b0<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u901a\u8fc7 abstract \u5173\u952e\u5b57\u5b9a\u4e49\u62bd\u8c61\u7c7b<\/li><li>\u4e0d\u80fd\u88ab\u5b9e\u4f8b\u5316,<strong>\u53ea\u6709\u7ee7\u627f\u4ed6\u7684\u5b50\u7c7b\u53ef\u4ee5<\/strong><\/li><li><strong>\u5982\u679c\u62bd\u8c61\u7c7b\u6709\u62bd\u8c61\u65b9\u6cd5,\u5fc5\u987b\u5728\u5b50\u7c7b\u4e2d\u5b9e\u73b0<\/strong><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u63a5\u53e3\">\u63a5\u53e3<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f7f\u7528 implements \u5173\u952e\u5b57\u8fdb\u884c\u5b9a\u4e49<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>abstract Dome Interfact{<br>    add()<br>}<br>class Xxx implements Interfact,xxx{ \/\/ \u7528\u9017\u53f7\u95f4\u9694\u53ef\u4ee5\u5b9a\u4e49\u591a\u4e2a\u63a5\u53e3\u7c7b\u578b <br>    <br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6df7\u5165-mixins\">\u6df7\u5165 Mixins<\/h2>\n\n\n\n<p>Dart\u4e2d\u4e0d\u5141\u8bb8\u591a\u4e2a\u7ee7\u627f, Mixins \u5b9e\u73b0\u7c7b\u4f3c\u7684\u591a\u7ee7\u627f<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>mixins \u7684\u7c7b\u578b<strong>\u4e0d\u80fd\u6709\u6784\u9020\u51fd\u6570<\/strong><\/li><li>\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u591a\u4e2a mixins \u7c7b<\/li><li>mixins \u4e0d\u662f\u7ee7\u627f,\u4e5f\u4e0d\u662f\u63a5\u53e3<\/li><li>\u591a\u4e2a mixins \u4e2d\u4f7f\u7528\u65f6 \u540e\u8005\u4f1a\u66ff\u6362\u524d\u8005\u7684\u540c\u540d\u65b9\u6cd5<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class A{}<br>class B{}<br>class C with A,B{} \/\/ \u6b64\u65f6\u7684 C \u5df2\u7ecf\u6709\u4e86 A \u548c B \u7684\u65b9\u6cd5\u548c\u5c5e\u6027<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u58f0\u660e\u7c7b ( \u540c JS ) \u9ed8\u8ba4\u6784\u9020\u51fd\u6570 \u5f62\u5f0f\u540c JS \u7684 Contructor \u547d\u540d\u6784\u9020\u51fd\u6570 \u5982\u679c\u5728\u5b9e\u4f8b\u5316\u4e3b\u52a8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-553","post","type-post","status-publish","format-standard","hentry","category-dart"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=553"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":554,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions\/554"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}